views:

239

answers:

4

Does anybody know what is the equivalent to $? in Windows command line? Is there any?

EDIT: $? is the UNIX variable which holds the exit code of the last process

+7  A: 

You want to check the value of %ERRORLEVEL%.

Tim Gilbert
Or rather just do an "if errorlevel ..."
Joey
+1  A: 
@echo off
run_some_command
if errorlevel 2 goto this
if errorlevel 1 goto that
goto end

:this
echo This
goto end

:that
echo That
goto end

:end
brownstone
Beware that the "if errorlevel" operation tests if the errorlevel variable is equal to *or* greater than the given number. So if you need to test for more than one possible value, the numbers must be checked in decreasing order (as shown in the example).
Andrew Medico
A: 

%errorlevel%

nos
+5  A: 

Windows Batch Files

%ERRORLEVEL% Returns the error code of the most recently used command. A non zero value usually indicates an error.

http://technet.microsoft.com/en-us/library/bb490954.aspx

Windows Powershell

$? Contains True if last operation succeeded and False otherwise. And

$LASTEXITCODE Contains the exit code of the last Win32 executable execution.

http://blogs.msdn.com/powershell/archive/2006/09/15/ErrorLevel-equivalent.aspx

Cygwin Bash Scripting

$? Expands to the exit status code of the most recently executed foreground program.

http://unix.sjcc.edu/cis157/BashParameters.htm

heavyd