I am running a program and want to see what its return code is (since it returns different codes based on different errors).
I know in Bash I can do this by running
echo $?
What do I do when using cmd.exe on Windows?
I am running a program and want to see what its return code is (since it returns different codes based on different errors). I know in Bash I can do this by running
What do I do when using cmd.exe on Windows? |
|||
|
Two ways... (1) The results are stored in a pseudo environment variable named errorlevel so...
(2) and a special syntax of the if command:
see For Example
Warning: if you set an environment variable name |
|||||||||||||
|
Use the built-in ERRORLEVEL Variable:
But beware if an application has defined an environment variable named ERRORLEVEL! |
|||||
|
Testing Instead of using the console-based C++ launcher mentioned elsewhere, though, a simpler alternative is to start a windowed application using the command prompt's |
|||||||
|
It might not work correctly when using a program that is not attached to the console, because that app might still be running while you think you have the exit code. A solution to do it in C++ looks like below:
|
||||
|