Sign in to follow this  
Followers 0
Amani

stdout getting closed on Run command following StdoutRead

6 posts in this topic

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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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().

Share this post


Link to post
Share on other sites

Okay, perhaps I misunderstood. I thought you were saying that my

invocation of StdoutRead was incorrect; your concern was that the

enclosing logic had a hole in it, which I can agree with.

Thanks for clarifying,

John

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  
Followers 0