Jump to content
Sign in to follow this  
DanielDaniel

Getting script return code with StdOutRead

Recommended Posts

DanielDaniel

Hi all,

I am running the following command:

$val = Run(@ComSpec & " /c " & chr(34) & $CmdLineRaw & chr(34), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

then reading the output with StdOutRead. All works fine, except for the fact that $val seems to contain a random return code from the command. The value of $CmdLineRaw is a VBS script that ends with the line WScript.Quit(2). But $val never gets the value of 2 (it looks like it contains the process ID of the command when it ran.

Before I added StdOutRead to Run command, $val was receiving the return code correctly.

Any ideas what I am doing wrong? I suspect that it is because I am using the "cmd /c" part, but using that was the only way I could get StdOutRead to work.

Cheers,

Daniel

Share this post


Link to post
Share on other sites
smartee

you are right. run returns the pid, runwait, however, returns the exit code.

Share this post


Link to post
Share on other sites
DanielDaniel

you are right. run returns the pid, runwait, however, returns the exit code.

Thanks! I changed Run for RunWait, and now the StdOut has stopped working. Here's the code:

$val = RunWait(@ComSpec & " /c " & chr(34) & $CmdLineRaw & chr(34), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Share this post


Link to post
Share on other sites
smartee

Thanks! I changed Run for RunWait, and now the StdOut has stopped working. Here's the code:

$val = RunWait(@ComSpec & " /c " & chr(34) & $CmdLineRaw & chr(34), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Probably you can try sending output to a file directly like iamtheky did

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.