up vote 1 down vote favorite
share [g+] share [fb]

Using bash, the exit code of the last thing that executed is stored in the $? shell variable:

foo
bar
echo $?  # prints exit code of `bar`

baz
echo $?  # prints exit code of `baz`

Is there an equivalent way to get this value if I'm running a script in cmd under Windows? (Note: resorting to things like running a Python script which then invokes its own library functions is not what I'm after here.)

link|improve this question
feedback

1 Answer

up vote 4 down vote accepted

%ERRORLEVEL% is the equivilent in windows

link|improve this answer
Keep in mind though, that this can fail if there is an actual environment variable named %ERRORLEVEL%. See also blogs.msdn.com/oldnewthing/archive/2008/09/26/8965755.aspx. So for added robustness you may want to delete the variable before accessing the pseudo-variable. – Joey Jan 15 '10 at 6:28
feedback

Your Answer

 
or
required, but never shown