Possible Duplicate:
How do I get the application exit code from a Windows command line?
In Unix/bash, I can simply say:
$ echo $?
to find out the return/exit code of a program, both from interactive and non-interactive shells.
Now, how can I do the equivalent in Windows/cmd.exe?
The which command in Linux is used to identify the location of executables. The where command is a Windows which equivalent in a command-line prompt (CMD). In a Windows PowerShell the alternative for the which command is the Get-Command utility.
To display the exit code for the last command you ran on the command line, use the following command: $ echo $?
Syntax: EXIT. Purpose: Exits a secondary command processor. Discussion. This command can be used when you are running an application program and want to start the DOS command processor, then return to your program.
Options. /c or /k command. Start a new cmd.exe process to execute the specified command and then exit ( /c ) or keep ( /k ) the process.
Use "errorlevel", like this:
IF ERRORLEVEL 1 GOTO ERROR
The errorlevel command is a little peculiar; it returns true if the return code was equal to or higher than the specified errorlevel. You can also write
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
This page is a good overview of how to use errorlevels in .bat files.
The equivalent is:
echo %ERRORLEVEL%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With