Analogous to the $?
in Linux, is there a way to get the exit status of a program in a Windows batch file (.bat
)?
Say for example the program has a System.exit(0)
upon successful execution, and a System.exit(1)
upon a failure, how do I trap these exit values in a .bat
file?
Something like:
java Foo
set 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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With