|
Return Codes (ERRORLEVEL) |
A return code is an integer value representing the state of a programs execution. Typically an error code of zero means that the program was successful and others indicate differemt levels of informational, warning or error events.
The return of a program or command typically sets the "ERRORLEVEL" environment variable.
A lot of programs return meaningful return codes while other badly written ones like Microsofts "cscript.exe" can return "0" even on complete failures caused by syntax errors!
You may need to do some testing to confirm how reliable the return codes are because of the "cscript" bug mentioned above I return my own non-zero return code to indicate success from critical VBSCRIPT code so I can reliably detect successful completion.
I have used the "dir" command twice below, once for a successful command (ERRORLEVEL=0) and a failed command (ERRORLEVEL=1):
C:\TMP>dir mvp.gif Volume in drive C is [C] SYSTEM Volume Serial Number is 7065-D79F Directory of C:\TMP 02/10/2004 04:01 PM 4,617 mvp.gif 1 File(s) 4,617 bytes 0 Dir(s) 369,788,317,696 bytes free C:\TMP>echo RC: %ERRORLEVEL% RC: 0 C:\TMP>dir NoSuch.gif Volume in drive C is [C] SYSTEM Volume Serial Number is 7065-D79F Directory of C:\TMP File Not Found C:\TMP>echo RC: %ERRORLEVEL% RC: 1
The "EXIT" command can be used in batch files to return a specific return code to the caller.
![]() ![]() |
| ![]() ![]() |