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

3

6

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?

Furthermore answered 10/11, 2008 at 7:30 Comment(0)
A
12

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.

Alexandra answered 10/11, 2008 at 7:39 Comment(1)
Be sure to check out the difference between ERRORLEVEL and %ERRORLEVEL%! blogs.msdn.com/oldnewthing/archive/2008/09/26/8965755.aspxHypnotic
P
6

The equivalent is:

echo %ERRORLEVEL%
Pocketknife answered 6/8, 2009 at 4:33 Comment(0)
C
2

check for the ERRORLEVEL

Chapbook answered 10/11, 2008 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.