If Errorlevel 1 (
Echo Errorlevel is 1 or higher
REM The phrase "1 or higher" is used because If Errorlevel 1 statement means:
REM If %Errorlevel% GEQ 1
REM Not If %Errorlevel% EQU 1
)
or
If "%Errorlevel%"=="1" (
Echo Errorlevel is 1
)
The script above would check the variable Errorlevel(built-in). The not
operator can be used.
Set "Test=%Errorlevel%"
If "%Test%" == "1" (
Echo Errorlevel is 1
)
This one also works.
Please note that some commands do not affect the errorlevel:
The following commands set but not clear errorlevel:
The following commands set exit codes but not the errorlevel:
The following commands set errorlevel but not the exit codes: