Jump to content

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


stg68
 Share

Go to solution Solved by Jos,

Recommended Posts

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

 

 

 

Link to comment
Share on other sites

  • Developers
  • Solution

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...