JohnOne Posted October 31, 2011 Posted October 31, 2011 Its not irrelevant, the op has said on numerous occaisions he does want to wait for the proccess to end before continuing the script, but still wants the exit code. Non of the code above can achieve that, it all waits for the process to end before continuing the script. I believe _ProcessGetExitCode($hPID) does just that, so while its being checked in a loop, the rest of the script can proceed until such time as there is an exit code to use. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Developers Jos Posted October 31, 2011 Developers Posted October 31, 2011 (edited) I don't think you're connecting the dots or trying to at least, I don't mean to be rude but check out some of the properties for the Run() function and try to come up with a method. I already showed you plenty.Honnestly think you aren't connecting the dots here. The Op was clear in his question about the need for the errorlevel but wanting to use Run in stead of RunWait.Jos Edited October 31, 2011 by 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.
Spiff59 Posted October 31, 2011 Posted October 31, 2011 (edited) Take advantage of one of the forms of inter-script communication and launch a child script (via Run or ShellExecute) each time you need to launch an application. Send the child script the handle of the master script, the app name and parms for the program to run and have the child script execute a runwait(), when the target application finishes the child can return the app name and exit code to your master script (which has never paused execution) and terminate. I adapted one of the commonly-used communication methods (WM_COPYDATA) in my (highly popular lol) Battle Checkers in the Examples Forum. The main program trades data with the AI modules in a manner that ought to work for you. Edited October 31, 2011 by Spiff59
vfear Posted October 31, 2011 Posted October 31, 2011 (edited) Honnestly think you aren't connecting the dots here.The Op was clear in his question about the need for the errorlevel but wanting to use Run in stead of RunWait. JosAnd you didn't check my posts prior to that one? I can relate to the problems that this guy has had because it's happened to me before as well, but I spent my time thinking about it and eventually found a work around for it. The scripts I was writing (for him) wasn't specifically what he wanted but I created more options for him, and other users have chimed in on the post to help him for what he specifically needed. Edited October 31, 2011 by vfear
robinj Posted September 8, 2016 Posted September 8, 2016 (edited) I was looking for a solution to this issue today in the forums and could not find anything that seemed to do the job required. IE. to return the exit errorlevel of an external command that was forked using the 'Run' command once it completes. I pulled a couple of functions from some other code I had that I probably aquired from someone else, but posting here because they do work expandcollapse popup;Run your program $PID = Run("MYPROGRAM.EXE") ;Retrieve the real windows process ID $SYSTEMPID = _ProcessGetHandle($VAR) ;Do your code in the meantime until MYPROGRAM terminates While ProcessExists($PID) Sleep(500) WEnd ;When it's complete, retrieve the errorlevel $ERRORLEVEL = _ProcessGetExitCode($SYSTEMPID) ;Display it MsgBox($MB_SYSTEMMODAL, "Exit ERRORLEVEL is ", $ERRORLEVEL) Exit ; Return handle of given PID Func _ProcessGetHandle($iPID) Local Const $PROCESS_QUERY_INFORMATION = 0x0400 Local $avRET = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", $PROCESS_QUERY_INFORMATION, "int", 0, "int", $iPID) If @error Then Return SetError(1, 0, 0) Else Return $avRET[0] EndIf EndFunc ;==>_ProcessGetHandle ; Get process exit code from handle Func _ProcessGetExitCode($hProc) Local $t_ExitCode = DllStructCreate("int") Local $avRET = DllCall("kernel32.dll", "int", "GetExitCodeProcess", "ptr", $hProc, "ptr", DllStructGetPtr($t_ExitCode)) If @error Then Return SetError(1, 0, 0) Else Return DllStructGetData($t_ExitCode, 1) EndIf EndFunc ;==>_ProcessGetExitCode Edited September 8, 2016 by robinj spelling
AutoBert Posted September 8, 2016 Posted September 8, 2016 Use RunWait and all is easy: Quote RunWait Runs an external program and pauses script execution until the program finishes. ... Return Value Success: the exit code of the program that was run. Failure: sets the @error flag to non-zero.
JohnOne Posted September 8, 2016 Posted September 8, 2016 On 10/31/2011 at 4:32 AM, readmedottxt said: I can't use RunWait because the external program may hang, suspending the script AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
AutoBert Posted September 8, 2016 Posted September 8, 2016 @JohnOne: i don't realized @readmedottxt (OP) and @robinj is same one user.
Developers Jos Posted September 8, 2016 Developers Posted September 8, 2016 Highly doubt they are the same and think it has everything to do with the the original question. 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.
AdamUL Posted September 8, 2016 Posted September 8, 2016 @robinj Those functions are now included in AutoIt. Also, in your script do not close the process handle at the end of your script. Look at the examples in the help file for _WinAPI_OpenProcess or _WinAPI_GetExitCodeProcess to do what you are requesting. _WinAPI_OpenProcess _WinAPI_GetExitCodeProcess Adam
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