In Unix/bash, I can simply say:
$ echo $?
to find out the return/exit code of a program, both from interactive and non-interactive shells.
Now, how can I do the equivalent in Windows/cmd.exe?
In Unix/bash, I can simply say:
$ echo $?
to find out the return/exit code of a program, both from interactive and non-interactive shells.
Now, how can I do the equivalent in Windows/cmd.exe?
Use "errorlevel", like this:
IF ERRORLEVEL 1 GOTO ERROR
The errorlevel command is a little peculiar; it returns true if the return code was equal to or higher than the specified errorlevel. You can also write
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
This page is a good overview of how to use errorlevels in .bat files.