Batch error handling

From wikinotes
Revision as of 00:38, 12 October 2018 by Will (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ERRORLEVEL

The %ERRORLEVEL% variable is roughly equivalent to bash's $?. A process-exit code of 0 indicates that a process completed successfully.

some-command.exe

IF %ERRORLEVEL% EQU 0 (
    echo No errors found
)

exit

REM exit the batch script early, with a return-code of 1
EXIT /B 1

REM exit the cmd.exe process with a return code of 1
EXIT 1