Jump to content

stdout getting closed on Run command following StdoutRead


Amani
 Share

Recommended Posts

It looks like my stdout handle for a child process is getting closed/mangled.

Roughly, what I have is

$myPID = Run($myCmd, "", @SW_HIDE, $STDOUT_CHILD)

While (ProcessExists($myPID))

$myStr = StdoutRead($myPID)

ConsoleWrite("myCmd output is " & $myStr & @CRLF)

WEnd

The $myCmd is just a batch script is some echo commands and

a delay. The command works as expected at the prompt.

But inside my autoscript, I find that I can grab the first block

of data from $myCmd with the StdoutRead. Following that, though,

I see a bunch of the following at the prompt where I execute my

autoscript:

The process tried to write to a nonexistent pipe.

It seems like somehow the stdout for the child command is getting

stomped on. I also tried changing my ConsoleWrite to ConsoleWriteError,

just in case my script was stomping on the stdout pipe

Any suggestions?

Link to comment
Share on other sites

Well, I changed a series of things, and I'm not sure which one resolved it, but it's now working.

Here's the new summary of the code:

$myPID = Run($myCmd, "", @SW_HIDE, $STDOUT_CHILD)

While (ProcessExists($myPID))
  Sleep(500)
  $myStr = StdoutRead($myPID)
  ConsoleWrite("myCmd output is " & $myStr & @CRLF)
WEnd
Link to comment
Share on other sites

I appreciate the reply. But looking at the helpful, I'm not sure I

see the delta between my use and it. Here's the (abbreviated)

sample from the helpful:

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

In my case, I'm not redirecting STDERR, but I'm not using

or consuming STDERR, so that shouldn't be an issue.

Can you elaborate on what you see as being incorrect?

Thank you,

John

Link to comment
Share on other sites

You end the loop when the app exits

While (ProcessExists($myPID))

The example in the helpfile ends when there's no data left

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop

Logic dictates that your way would miss data that was written between the StdoutRead() and ProcessExists().

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...