Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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

C:\> echo %ERRORLEVEL%
0

C:\> cmd /c exit 1

C:\> echo %ERRORLEVEL%
1

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
1  
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
add comment

Your Answer

 
discard

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.