xq1xq1xq1 Posted March 25, 2008 Share Posted March 25, 2008 Hi, I want to do a check on whether or not an Error Occurs after this statement is issued: $rtn_code = Run(@ComSpec & " /c " & $cmd, $pgm_dir, "") According to the documentation, the $rtn_code will be the PID of the process spawned or an error code generated by the execution of the command. In order to put a correct check for an error, I need to know what the lowest possible PID that is valid for Windows. Thus if the value is below this number, it is an Error Code and not a PID. Thanx Link to comment Share on other sites More sharing options...
weaponx Posted March 25, 2008 Share Posted March 25, 2008 It should return zero in the event of failure...and @ERROR will be set. Link to comment Share on other sites More sharing options...
DarkMatter Posted March 25, 2008 Share Posted March 25, 2008 What command are you issuing threw ComSpec? If its a standard console window you could try to use the STDERR or STDOUT stream to check for errors. [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 25, 2008 Author Share Posted March 25, 2008 Hi,I want to do a check on whether or not an Error Occurs after this statement is issued:$rtn_code = Run(@ComSpec & " /c " & $cmd, $pgm_dir, "")According to the documentation, the $rtn_code will be the PID of the process spawned or an error code generated by the execution of the command.In order to put a correct check for an error, I need to know what the lowest possible PID that is valid for Windows. Thus if the value is below this number, it is an Error Code and not a PID.ThanxAlternatively, what is the maximum value that an Error Return Code can be from a program - then anything above that number would be a process.... Link to comment Share on other sites More sharing options...
DarkMatter Posted March 25, 2008 Share Posted March 25, 2008 Alternatively, what is the maximum value that an Error Return Code can be from a program - then anything above that number would be a process....Windows XP SYSTEM error codes go from 0 - 14080. PIDs will fall within that range. [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 25, 2008 Author Share Posted March 25, 2008 It should return zero in the event of failure...and @ERROR will be set.I generated an error in the parameters used in the TSHARK command being sent to CMD.The @error value remained at 0The Return Code from RUN was the PID.If I use the RUNWAIT function then I get 0 if the command ran without error and I get the Error Number if the command fails. I am trying to get this functionality with the RUN command.What I am trying to accomplish is to ALLOW the user to a window in which to interact with the script when processing several consecutive commands.If I only use the RUNWAIT, the user's interaction is not seen by the script. Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 25, 2008 Author Share Posted March 25, 2008 Windows XP SYSTEM error codes go from 0 - 14080. PIDs will fall within that range.Thanx for the informaton - this means that I can not distinguish between a PID and an Error Code returned from a process then, correct? Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 25, 2008 Share Posted March 25, 2008 The return error code (which few programs ever use anymore) is a 32 bit integer in Visual C++. Technically a program can return up to 2^31-1. Link to comment Share on other sites More sharing options...
weaponx Posted March 25, 2008 Share Posted March 25, 2008 To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)After running the requested program the script continues. To pause execution of the script until the spawned program has finished use the RunWait function instead.By default the script will terminate with a fatal error if the Run function fails. To set @error 1, @extended to GetLastError() Windows API and return 0 as an indication of failure, see AutoItSetOption.Maybe try Opt("RunErrorsFatal", 0) Link to comment Share on other sites More sharing options...
DarkMatter Posted March 25, 2008 Share Posted March 25, 2008 (edited) Thanx for the informaton - this means that I can not distinguish between a PID and an Error Code returned from a process then, correct?Correct, what I was referring to here was just standard system error codes.The return error code (which few programs ever use anymore) is a 32 bit integer in Visual C++. Technically a program can return up to 2^31-1.What Richard Robertson said is technically the correct answer. Edited March 25, 2008 by MattWise [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 26, 2008 Author Share Posted March 26, 2008 Thanx everyone for you input. What I was attempting to do was to determine a ProcessID for a process initiated by the RUNWAIT statement. I wanted to do this to KILL this process at the user's discretion after the process had started. What I found out was that AUTOIT will not look for User Interaction until the RUNWAIT has finished (thus the name RUNWAIT). I then attempted to use the 'RUN" command with a 'POLL' loop waiting for when the process had finished and looking for user interaction. In this case I could not determine if the process ended successfully or with an error. My solution was to add a 'CHECKBOX' that is checked after the process has completed executing and if checked stop executing the next in the list. Does anyone have a way of accomplishing this task? Thanx Link to comment Share on other sites More sharing options...
weaponx Posted March 26, 2008 Share Posted March 26, 2008 You are very confused...Run() returns ProcessIDRunWait() returns exit codeIf you need to get the exit code of a process using Run() you must use this UDF:http://www.autoitscript.com/forum/index.php?showtopic=23096 Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 26, 2008 Author Share Posted March 26, 2008 You are very confused...Run() returns ProcessIDRunWait() returns exit codeIf you need to get the exit code of a process using Run() you must use this UDF:http://www.autoitscript.com/forum/index.php?showtopic=23096Okay then how Can I determine if a ProcessID created by the RUN command terminates with 'not normal' return/exit code?Thanx for clearing up the confustion! Link to comment Share on other sites More sharing options...
weaponx Posted March 26, 2008 Share Posted March 26, 2008 Okay then how Can I determine if a ProcessID created by the RUN command terminates with 'not normal' return/exit code?Thanx for clearing up the confustion!Well you test with RunWait()...$exitcode = RunWait()MsgBox(0,"",$exitcode)Whatever the exit code is when its successful you write that down...if it fails write that down, force it to close if you have to. Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 26, 2008 Author Share Posted March 26, 2008 Well you test with RunWait()...$exitcode = RunWait()MsgBox(0,"",$exitcode)Whatever the exit code is when its successful you write that down...if it fails write that down, force it to close if you have to.You are correct in that RUNWAIT returns an ExitCode.What i am trying to accomplish is to give the user the ability to effectively kill a Process spawned by AUTOIT.As I noted above, RUNWAIT does not work as the script will not accept user input while it is WAITING.Thus I need to use the RUN command and the loop waiting for the process to finish.The issue with the RUN command is that the value returned is a Process ID.How can I determine if an 'ERROR' code is generated by the process being executed like that of RUNWAIT shown above?Thanx Link to comment Share on other sites More sharing options...
weaponx Posted March 26, 2008 Share Posted March 26, 2008 Wow we are not on the same wavelength. You use RunWait() to determine all of the possible exit codes based on your program running successfully or unsuccessfully. This is for testing ONLY! You need to remember the various exit codes for use with Run() and the function I posted for you. Link to comment Share on other sites More sharing options...
xq1xq1xq1 Posted March 26, 2008 Author Share Posted March 26, 2008 A few posts up, UDF was mentioned. What is a UDF? Thanx Link to comment Share on other sites More sharing options...
FreeFry Posted March 26, 2008 Share Posted March 26, 2008 User Defined Function. 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