How to get the exit status of a Java program in Windows batch file
Something like:
java Fooset exitcode=%ERRORLEVEL%echo %exitcode%
It's important to make this the absolute next line of the batch file, to avoid the error level being overwritten :)
Note that if you use the
IF ERRORLEVEL number
"feature" of batch files, it means "if the error level is greater than or equal to number
" - it's not based on equality. I've been bitten by that before now :)
Raymond Chen has a good blog post named ERRORLEVEL is not %ERRORLEVEL%. Worth checking out.
Also worth noting is that the REM command which most people think of as comments, really aren't. The REM command is a nop command which always succeeds. After a REM, the error level is always 0. So
willalwaysfail.batREM unless you insert a comment after itif errorlevel 1 goto fail
will never fail...