Errorlevels set by commands on Windows

Santhosh picture Santhosh · Jan 26, 2010 · Viewed 7.2k times · Source

I have a batch program that calls several child batch programs and they make extensive use of various Windows commands. In case of error, I would like to provide logging information about the error details to the user.

How do I know what are the various error codes (a number in the range 0 to 256) that these commands can return and what are their interpretations in English?

Answer

Joey picture Joey · Jan 26, 2010

If you really are on DOS (which I highly doubt) then the only way is

command
if errorlevel 255 echo 255
if errorlevel 254 echo 254
if errorlevel 253 echo 253
...
if errorlevel 1 echo 1
if errorlevel 0 echo 0

The interpretations in a natural language are then up to you, as you should know what exactly you did try there.

Note that on Windows you can usually just do

command
echo %errorlevel%