ERRORLEVEL
will contain the return code of the last command. Sadly you can only check >=
for it.
Note specifically this line in the MSDN documentation for the If
statement:
errorlevel Number
Specifies a true
condition only if the previous program
run by Cmd.exe returned an exit code
equal to or greater than Number.
So to check for 0 you need to think outside the box:
IF ERRORLEVEL 1 GOTO errorHandling
REM no error here, errolevel == 0
:errorHandling
Or if you want to code error handling first:
IF NOT ERRORLEVEL 1 GOTO no_error
REM errorhandling, errorlevel >= 1
:no_error
Further information about BAT programming: http://www.ericphelps.com/batch/
Or more specific for Windows cmd
: MSDN using batch files
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…