Batch file error level
%ERRORLEVEL% is an environment variable that contains the last error level or return code in the batch file – that is, the last error code of the last command executed. Error levels may be checked by using the %ERRORLEVEL% variable as follows:
IF %ERRORLEVEL% NEQ 0 ( DO_Something )
A common method of returning error codes from batch files is to use the command EXIT /B %ERRORLEVEL%.
For custom return codes, use the EXIT /B <exitcodes> command.
Example:
In the below example, if the condition is met, the script will terminate with the exit code 0. If the condition isn’t met, then the exit code will be 1.
if [[ "$(whoami)" != root ]]; then echo "Not root user." exit 1 fi echo "root user" exit 0
Output:
Batch Script – Return code
Return codes are the codes returned by programs when they are executed. If the command line is successful, it should return zero; if it is not successful, it should return non-zero. If the test fails, a non-zero value indicates the error number, and the user can attempt to resolve it by navigating to the error message.
The test may also return an exit code. A program’s or utility’s exit code usually appears when it finishes or terminates.
The list below includes some of the non-zero exit codes (with their respective errors) that programs may return
Error Code | Description |
---|---|
0 | Successful completion of the program. |
1 | This error indicates that the Windows command prompt has attempted to execute an unrecognized action |
2 | An error indicating that the file could not be found in the specified location |
3 | An error message indicated that the specified path could not be found. |
5 | An indication that the user is not authorized to access the resource |
90090×2331 | This error occurs when you misspell the command, application name, or path when configuring an Action. |
2212254950xC0000017-1073741801 | The error message tells you that Windows has run out of memory. |
32212257860xC000013A-1073741510 | This indicates that the user terminated the application |
32212257940xC0000142-1073741502 | The message indicating that the application was launched on a desktop to which the current user doesn’t have access |
Contact Us