Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After a program exits from command line, how can I check the exit code?

share|improve this question
up vote 3 down vote accepted

ERRORLEVEL will contain the exit code of the last command. Example:

C:\> echo %ERRORLEVEL%

C:\> cmd /c exit 1

C:\> echo %ERRORLEVEL%

C:\> IF ERRORLEVEL 1 ECHO An error occurred!
An error occurred!

Note that in the example above, the IF statement will succeed when ERRORLEVEL is 1 or more.

share|improve this answer
You can also check for other relationships ("exactly equal", for example): IF %ERRORLEVEL% EQU 1 ECHO Error – Dennis Williamson Nov 22 '10 at 15:48
sh-style something || iffailed and something && ifsuccess are possible too. – grawity Nov 22 '10 at 16:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.