Sign in to follow this  
Followers 0
bjkeith

Getting errorlevel from DOS command line?

3 posts in this topic

I'm having trouble getting the errorlevel from a command run in a DOS shell. Basically I'm trying to run ant to build some java code automatically with the following:

$JavaBuild = RunWait('ant.bat -logfile ant.log')

The RunWait works fine, but when I do an evaluation of $JavaBuild I seem to get the success/failure code for the RunWait, not the actual ant command.

For example, using:

$SuccessMsg = "Build successful."

$FailureMsg = "Build failure - aborting rest of nightly build..."

If ($JavaBuild = 0) Then

_FileWriteLog($sLogPath, $SuccessMsg)

Else

_FileWriteLog($sLogPath, $FailureMsg)

failuremail()

Exit(1)

Endif

I always get $JavaBuild =0 whether the ant command succeeded or failed. Note that manually running the command followed by echo %errorlevel% gives the expected result (ie success = 0, failure = 1)

Am I missing something blindingly obvious? I know I could work around this by subsequently running:

echo %errorlevel > somefile.txt

then parsing somefile.txt, but it seems rather painful :)

If someone has a better way or can explain what I'm not understanding about what RunWait returns, I'd appreciate it.

cheers,

Ben

Share this post


Link to post
Share on other sites



Gee, it appears that AutoIt does not like error codes from BATCH files ....

After much experimenting, this information, led me to the following solution:

Create an AutoIt script that contains the following line:

Exit(1)

Compile the script into SetErr.exe or something.

Modify your ant.BAT file so that it runs SetErr.exe right before exiting if there is a failure condition.

Hope that works for you


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Gee, it appears that AutoIt does not like error codes from BATCH files ....

After much experimenting, this information, led me to the following solution:

Create an AutoIt script that contains the following line:

Exit(1)

Compile the script into SetErr.exe or something.

Modify your ant.BAT file so that it runs SetErr.exe right before exiting if there is a failure condition.

Hope that works for you

<{POST_SNAPBACK}>

Thanks, I searched for errorlevel etc in the forum, didn't think to search for batch files :)

I've since found some other evidence of Windows batch file funniness with ant:

http://issues.apache.org/bugzilla/show_bug.cgi?id=13655

Thanks again for the rapid response and the tip.

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  
Followers 0