Dos Error Levels
Contents |
Challenges C# Getting Started Examples Development Software Books KiXtart Getting Started Examples Links Tools Books Perl Getting Started Examples Links Tools Books PowerShell Getting Started Examples Links Tools Books Regular Expressions Getting Started Expressions Examples Links batch file check errorlevel Tools Books Rexx Getting Started Examples OS/2 LAN Server Links Tools Books VBScript &
Dos Error Codes
WSH Getting Started VBScript Techniques Examples HTA & WSC Examples Links Tools Books Challenges Technologies WMI Getting Started Examples Links
Dos Error Codes List
Tools Books ADSI Getting Started Examples Links Tools Books Silent Installs General Windows Installer Specific Software Software Requirements Hardware Requirements Books Batch Files Windows Resource Kits KiXtart Perl PowerShell Regular Expressions Rexx VBScript &
Dos Set Errorlevel
WSH C# WMI ADSI HTML, JavaScript & CSS Off-Topic Scripting Tools Batch Utilities Resource Kits Compilers Editors Code Generators Regular Expressions Automation Tools VBScript Add-Ons Visual Studio Printing Tools Inventory Tools Shell Extensions File Viewers Backup Security The making Of... Miscellaneous Tweaks Web Stuff Conversions My Photo Galleries About This Site Disclaimer News FAQ Search What's New Objective Site Policy Your Preferences Credits The Making Of... Contact Failed Mail dos display errorlevel Donate Errorlevels The correct name for errorlevels would be return codes. But since the DOS command to determine the return code is IF ERRORLEVEL, most people use the name errorlevel. Errorlevels are not a standard feature of every command. A certain errorlevel may mean anything the programmer wanted it to. Most programmers agree that an errorlevel 0 means the command executed successfully, and an errorlevel 1 or higher usually spells trouble. But there are many exceptions to this general rule. IF ERRORLEVEL construction has one strange feature, that can be used to our advantage: it returns TRUE if the return code was equal to or higher than the specified errorlevel. This means most of the time we only need to check IF ERRORLEVEL 1 ... and this will return TRUE for every non-zero return code. In Windows NT4/2000/XP this may sometimes fail, since some executables return negative numbers for errorlevels! However, this can be fixed by using the following code to check for non-zero return codes: IF %ERRORLEVEL% NEQ 0 ... Use the code above wherever you would have used IF ERRORLEVEL 1 ... in the "past". Thanks for Noe Parenteau for this tip. To determine the exact return code the previo
and Start program / application Action events (67000, 67002, 67202, 67402) may end with errorlevels or exit codes, that indicate the termination dos ping errorlevel status of executed Command or Application. They can help in dos errorlevel 9009 finding the particular reason of command's or application's termination. Although Automation Workshop shows codes in decimal format, dos beep codes they are also referred as hexadecimal or negative decimal values.Exit codeDetails0Program suseccfully completed.1Incorrect function. Indicates that Action has attempted to execute non-recognized command in Windows command http://www.robvanderwoude.com/errorlevel.php prompt cmd.exe.2The system cannot find the file specified. Indicates that the file can not be found in specified location.3The system cannot find the path specified. Indicates that the specified path can not be found.5Access is denied. Indicates that user has no access right to specified resource.9009
0x2331Program is not recognized as an internal or http://www.febooti.com/products/automation-workshop/online-help/events/run-dos-cmd-command/exit-codes/ external command, operable program or batch file. Indicates that command, application name or path has been misspelled when configuring the Action.3221225477
0xC0000005
-1073741819Access violation.Indicates that the executed program has terminated abnormally or crashed.3221225495
0xC0000017
-1073741801Not enough virtual memory is available.Indicates that Windows has run out of memory.3221225786
0xC000013A
-1073741510The application terminated as a result of a CTRL+C. Indicates that the application has been terminated either by user's keyboard input CTRL+C or CTRL+Break or closing command prompt window.3221225794
0xC0000142
-1073741502The application failed to initialize properly. Indicates that the application has been launched on a Desktop to which current user has no access rights. Another possible cause is that either gdi32.dll or user32.dll has failed to initialize.3221226505
0xC0000409
-1073740791Stack buffer overflow / overrun. Error can indicate a bug in the executed software that causes stack overflow, leading to abnormal termination of the software.3221225725
0xC00000FD
-1073741571Stack overflow / exhaustion. Error can indicate a bug in the executed software that causes stack overflow, leading to abnormal termination of the software.376250
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting http://stackoverflow.com/questions/6812484/batch-file-test-error-level ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the http://stackoverflow.com/questions/10935693/foolproof-way-to-check-for-nonzero-error-return-code-in-windows-batch-file Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up batch file test error level up vote 4 down vote favorite 2 I'm trying to conditionally run an exe from a batch file conditionally upon another exe executing successfully. I've tried a few different combinations of IF and dos error ERRORLEVEL but none seem to work "..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008r2 IF %ERRORLEVEL% 1( "..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008 ) Pause Gives me the error 1( was unexpected at this time. Where am I going wrong here? error-handling batch-file share|improve this question asked Jul 25 '11 at 6:32 Daniel Powell 4,96734079 Hmm, perhaps 1( is wrong? Have you tried 1 ( with a space? And by the way use either if errorlevel 1 (... or if %errorlevel%==1 (... –jeb Jul 25 '11 at dos error codes 6:44 @jeb: That seems to be the actual cause of the error, I mean, the mixed up syntax in the OP's script. –Andriy M Jul 25 '11 at 22:49 add a comment| 2 Answers 2 active oldest votes up vote 17 down vote accepted IF ERRORLEVEL is a special syntax supported since the DOS days, the %ERRORLEVEL% variable support was added in WinNT. The original syntax is used like this: call someapp.exe if errorlevel 1 goto handleerror1orhigher if errorlevel 0 echo succuess... To use the variable, use the normal IF syntax: if %errorlevel%==0 echo success... Note that %errorlevel% stops working if someone does set errorlevel=foo and it might not get updated for internal cmd.exe commands. An alternative solution is to use &&: call someapp.exe && (echo success) || (echo error!) share|improve this answer answered Jul 25 '11 at 14:40 Anders 47.2k74994 I've only used either && or ||, never both of them on one line. Didn't know that together they essentially work like IF...ELSE. That's a nice thing to learn, thanks! –Andriy M Jul 25 '11 at 22:46 4 if errorlevel 0 means "if errorlevel is greater than or equal zero", that is, any value. The right way to ask for success is: if not errorlevel 1 echo success... –Aacini Jul 26 '11 at 1:31 @Aacini: well yes, but I'm checking 1 before 0, that is a valid way to do it. –Anders Jul 26 '11 at 14
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Foolproof way to check for nonzero (error) return code in windows batch file up vote 14 down vote favorite 10 Intro There's a lot of advice out there for dealing with return codes in batch files (using the ERROLEVEL mechanism), e.g. Get error code from within a batch file ERRORLEVEL inside IF Some of the advice is to do if errorlevel 1 goto somethingbad, while others recommend using the %ERRORLEVEL% variable and using ==, EQU, LSS, etc. There seem to be issues within IF statements and such, so then delayedexpansion is encouraged, but it seems to come with quirks of its own. Question What is a foolproof (i.e. robust, so it will work on nearly any system with nearly any return code) way to know if a bad (nonzero) code has been returned? My attempt For basic usage, the following seems to work ok to catch any nonzero return code: if not errorlevel 0 ( echo error level was nonzero ) windows batch-file share|improve this question asked Jun 7 '12 at 16:13 Pat 7,28184785 add a comment| 1 Answer 1 active oldest votes up vote 30 down vote accepted Sorry, your attempt is not even close. if not errorlevel 0 is only true if errorlevel is negative. If you know that errorlevel will never be negative, then if errorlevel 1 (echo error level is greater than 0) If you must allow for negative errorlevel, and are not within a parenthesized block of code, then set "errorlevel=1" set "errorlevel=" if %errorlevel% neq 0 (echo error level is non-zero) Note - I edited my answer to explicitly clear any user d