Search the Community
Showing results for tags 'processwaitclose'.
Initial Problem I've written several scripts with the following sequence: Execute a program using Run w/stdout+stderr captured Typically processes all the files in one directory tree to populate a second tree Execute a second program (also with Run) to monitor the products of the first program and Display a progress bar (percentage of output files complete) Also monitor the first program's process and exit when it terminates The script then calls ProcessWaitClose (no timeout) on the first program's process and Checks the first program's results Kills the monitor program if it hasn't already exited on its own. Sometimes, ProcessWaitClose returns 1 with @error = 0 and @extended = 0xCCCCCCCC (actually, 0xFFFFFFFFCCCCCCCC), which seems ambiguous: the documentation says that @error = non-zero and @extended = 0xCC... means an invalid PID (unclear what the return value is), and 1 is returned for non-existent processes (but no mention of @extended). The 1/0/0xCC... result seems to occur when the first program exits very quickly (with or without an error). Since the exit value is not available, the script scans the program's output and tries to determine whether it ran successfully. This has gotten complicated and unreliable. Partial Fix I've now implemented a much simpler approach that works for most cases: Modify the monitor program so that it ignores the other program's process (the monitor always gets killed by the script anyway) Execute the monitor program first using Run, then execute the processing program with RunWait When RunWait returns, the child process exit value is available, so the script can ignore its output (which isn't available anyway) If the monitor program is still running, kill it. Remaining Issue However, there are still a couple of cases where it's necessary to get both the exit value from the processing program and its output. Since RunWait doesn't capture stdout and stderr for the parent script, it's looking like I'll have to call RunWait and redirect the 2 streams to a temp file and then scan it. Also, to do the redirect, I think I'll have to use @ComSpec to execute the processing program, which adds an undesired layer. Does anybody have a better (cleaner) way to handle these cases?
AutoIT v126.96.36.199. Win7 64-bit Problem Description: @error returns 0 if $iPID closed before timeout reached. Expected not 0. Based on help: “Failure: 0 if the wait timed out” ;and this works. “Success: 1 and sets @extended to the exit code of the process.”; cannot catch 1 (or not @error=0) Goal: Distinguish between 10 seconds timeout reached and $iPID closed prior to 10 seconds timeout Seems like I am missing something. Thank you for your help! #include <MsgBoxConstants.au3> $iPID = Run("notepad.exe") ProcessWaitClose($iPID, 10) If @error = 0 Then MsgBox($MB_SYSTEMMODAL, "", "Timeout reached! Notepad was running more than 10 seconds") ; this works Else MsgBox($MB_SYSTEMMODAL, "", "Notepad was closed prior to 10 seconds timeout"); this does not. Was expecting @error<>0 EndIf