What is the Windows / cmd.exe equivalent for Linux / bash $? - program exit / return code?

Possible duplicate:
How to get application exit code from windows command line?

On Unix / bash, I can just say:

$ echo $?

to find out the return / exit code of the program, both from interactive and non-interactive shells.

Now, how can I do the equivalent in Windows / cmd.exe?

+6
windows cmd
source share
3 answers

Use "errorlevel", for example:

IF ERRORLEVEL 1 GOTO ERROR 

The errorlevel command is a bit strange; it returns true if the return code is equal to or higher than the specified error level. You can also write

 IF %ERRORLEVEL% NEQ 0 GOTO ERROR 

This page is a good overview of how to use error levels in .bat files.

+12
source share

Equivalent:

 echo %ERRORLEVEL% 
+6
source share

check the value of ERRORLEVEL

+2
source share

All Articles