Amani Posted November 22, 2010 Share Posted November 22, 2010 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 More sharing options...
Amani Posted November 22, 2010 Author Share Posted November 22, 2010 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 More sharing options...
AdmiralAlkex Posted November 22, 2010 Share Posted November 22, 2010 Your code isn't really correct, see the example for StdoutRead in the helpfile. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Amani Posted November 22, 2010 Author Share Posted November 22, 2010 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 More sharing options...
AdmiralAlkex Posted November 22, 2010 Share Posted November 22, 2010 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(). .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Amani Posted November 22, 2010 Author Share Posted November 22, 2010 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now