Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Windows/cmd.exe equivalent of Linux/bash's $? -- the program exit/return code? [duplicate]

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?

like image 456
user10955 Avatar asked Nov 10 '08 07:11

user10955


People also ask

Which Linux command is equivalent to Windows?

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.

How do I find my return code using cmd?

To display the exit code for the last command you ran on the command line, use the following command: $ echo $?

What is exit command in cmd?

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.

What is cmd.exe K?

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.


2 Answers

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.

like image 117
JesperE Avatar answered Oct 13 '22 20:10

JesperE


The equivalent is:

echo %ERRORLEVEL%
like image 23
ebryn Avatar answered Oct 13 '22 20:10

ebryn