Questions tagged [errorlevel]
238 questions
89
votes
14 answers
What is the easiest way to reset ERRORLEVEL to zero?
I have a post-build event that runs some commands for a c# project. The last command would sometimes cause the ERRORLEVEL value not equals to zero and then the build fails.
I want to append an extra line of command to always set the ERRORLEVEL value…

user95319
- 1,213
- 1
- 8
- 12
65
votes
6 answers
check if command was successful in a batch file
How within a batch file to check if command
start "" javaw -jar %~p0/example.jar
was successful or produced an error?
I want to use if/else statements to echo this info out.

31415926
- 3,811
- 7
- 47
- 78
54
votes
1 answer
accessing ERRORLEVEL from bash script
I have an application that only works properly when called from a windows command prompt. Something to do with the input/output streams.
So I can call it from a bash script by passing it as an argument to cmd.
cmd /c "badapp"
This works fine -…

shipshape
- 691
- 1
- 6
- 5
42
votes
2 answers
ERRORLEVEL inside IF
Just stumbled into a weird thing with %ERRORLEVEL% and wanted to see if anyone knows why and if there's a way to fix it. Essentially, it seems as if commands executed inside if statements don't set the %ERRORLEVEL% variable. The ERRORLEVEL (as in IF…

Srekel
- 2,183
- 3
- 21
- 26
40
votes
1 answer
Best way to view a command return code in DOS
Sometimes I run a command in cmd such as:
fc /b file1 file2
and would like to see the return code from fc. Is there a simple way to do this?

Warpin
- 6,971
- 12
- 51
- 77
31
votes
1 answer
What are the ERRORLEVEL values set by internal cmd.exe commands?
The ERRORLEVEL is a value returned by most cmd.exe commands when they end that change depending on a series of conditions, so knowing the value that the commands return is valuable information that may aid to write better Batch files. All external…

Aacini
- 65,180
- 12
- 72
- 108
29
votes
3 answers
Errorlevel in a For loop (Windows batch)
I have the following windows batch code:
for %%i in (iidbms iigcc iigcd dmfacp dmfrcp rmcmd qwerty) do (
tasklist | findstr /i %%i
echo %errorlevel%
if %errorlevel% == 0 (echo %%i ok process found %errorlevel%)
if %errorlevel% == 1 (echo %%i…
user461487
25
votes
7 answers
System.exit(num) or throw a RuntimeException from main?
I've got a single threaded app that should set the DOS errorlevel to something non-zero if there is a problem. Is it better to throw a RuntimeException, or to use System.exit(nonzero)? I don't need the stack trace, and I don't expect this app to be…

VarV
- 253
- 1
- 3
- 5
24
votes
2 answers
Which cmd.exe internal commands clear the ERRORLEVEL to 0 upon success?
A frequent method to handling errors within Windows batch scripts is to use things like
if errorlevel 1 ... or if %errorlevel% neq 0 .... Often times one wants the error handling code to preserve the ERRORLEVEL.
I believe all external commands will…

dbenham
- 127,446
- 28
- 251
- 390
18
votes
4 answers
Exiting batch with `EXIT /B X` where X>=1 acts as if command completed successfully when using && or || operators between batch calls
I'm trying to chain a series of .bat files using the EXIT /B X command to return success or failure and && and || for conditional running of the next .bat (e.g. a.bat && b.bat).
Regardless of whether I call EXIT /B 0 or anything else to end a.bat,…

Jordan Evens
- 405
- 1
- 4
- 14
18
votes
2 answers
PostBuild Event fails in Visual Studio after SignTool.exe error
We have a project in Visual Studio 2010 that runs a batch file in the post-build event. That batch calls to signtool.exe from Microsoft SDK to sign and timestamp the binary.
Timestamp servers (we use…

Vladimir Shutow
- 1,028
- 1
- 14
- 22
17
votes
1 answer
Official MS reference for cmd.exe %errorlevel% 9009
So I know from experience that running a valid program from cmd.exe and checking the %errorlevel% will return a 0:
C:\>dir logo.bmp
Volume in drive C has no label.
Volume Serial Number is 5283-A7A2
Directory of C:\
05/22/2008 12:43 PM …

AWT
- 3,657
- 5
- 32
- 60
14
votes
2 answers
findstr exit codes/errorlevel
I have a program that is using findstr, and when the string is found the errorlevel returns 0 and when the string is not found the errorlevel returns 1. Alright, that's fine I can deal with that.
Where the issue lies is I cannot find any official…

Saltz3
- 324
- 1
- 4
- 15
13
votes
1 answer
Powershell fails to return proper exit code
When executing a Powershell script (in 2.0) using the -File command line switch, and explicitly defining the input parameters in Param, the exit code is always "0" (never fails) instead of properly returning the defined or expected error code.
This…

JonnyG
- 759
- 1
- 13
- 25
12
votes
2 answers
get return code from plink?
In a DOS batch script, I'm running a single command on a remote (also windows) computer using plink. Formerly, this command was only run on the local machine, and was relying on the return code to determine success. Is there a way to easily get…

Nate
- 12,499
- 5
- 45
- 60