Jump to content

Reading a script's return value?


Recommended Posts

EDIT: The problem is that %errorlevel% gets set back to zero before I read it...

RunWait("C:\SomeCompiledScript.exe")

MsgBox(0,"", EnvGet("errorlevel"))

Exit

====

How do you read a program's return value / exit code / errorlevel in AutoIt?

I can only figure out how to do it with a batch file:

REM Sample Batch file
@echo off
"C:\SomeCompiledScript.exe"
echo Return value was %errorlevel%
pause

Thanks

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

EDIT: The problem is that %errorlevel% gets set back to zero before I read it...

RunWait("C:\SomeCompiledScript.exe")

MsgBox(0,"", EnvGet("errorlevel"))

Exit

====

How do you read a program's return value / exit code / errorlevel in AutoIt?

I can only figure out how to do it with a batch file:

REM Sample Batch file
@echo off
"C:\SomeCompiledScript.exe"
echo Return value was %errorlevel%
pause

Thanks

Does Run/RunWait return the exit code from the program? I've never tried, but it may.
Link to comment
Share on other sites

I'm an idiot. Valik put me on the right track.

$var = RunWait("C:\SomeProgram.exe")

MsgBox(0, "Return value is", $var)

Note: You must use RunWait instead of Run, but that's not a bug (it really is a feature)

:iamstupid:

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

I was going to suggest

RunWait("C:\SomeCompiledScript.exe")

$Var = @error

MsgBox(0,"", $Var)

Exit

I just tested it and it returns 0

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

:iamstupid: I looked at the source code last night to see if it was setting the return value, but I only looked at the code for Run. It was late and it never ocurred to me that Run wouldn't have a return code because of how it works. I didn't even look at RunWait. So, I read your post, I open the source again to have a look, and the cursor is almost on the line that assigns the programs return value to RunWait's return value. :iamstupid:

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...