Jump to content
Sign in to follow this  
stg68

ProcessWaitClose($iPID,10). Unable to catch Return Value Success (1)

Recommended Posts

stg68

AutoIT v3.3.10.2. 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

 

 

 

Share this post


Link to post
Share on other sites
Jos

You need to test the returned value, not the @error. The script should be:

$iPID = Run("notepad.exe")
$rc = ProcessWaitClose($iPID, 10)
If $rc = 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

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
stg68

Thank you so much!

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  

  • Similar Content

    • tremolux66
      By tremolux66
      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?
×