How to get the exit status of a Java program in Windows batch file

pugmarx picture pugmarx · May 20, 2009 · Viewed 38.9k times · Source

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?

Answer

Matthew Flaschen picture Matthew Flaschen · May 20, 2009

Use %ERRORLEVEL%. Don't you love how batch files are clear and concise? :)