ERRORLEVEL is an alternate name (included for compatibility with CMD) for the ? variable, and is the exit code of the last external command. Many programs return 0 to indicate success and a non-zero value to signal an error. However, not all programs return an exit code. If no explicit exit code is returned, the value of ERRORLEVEL is undefined.


WARNING: For compatibility with CMD, some internal commands, e.g., DIR, also set this variable to the same value as the variable _?, which destroys the code from the last external command. If you need to preserve the return value of the external command, save the value in a variable immediately upon command completion, and use the saved variable instead. We also strongly recommend that for internal commands you query the _? variable instead.


See also _?