... please wait while loading ...

To view the complete site without permanently having to scroll, your browser-window should be maximized to support your screen-resolution of .
Burgdorf
Anja Oelkers

facebook google

  17.377.089 Nedstat Basic - Kostenlose web site statistiken Persönliche Homepage webseite Zähler
Kostenlose Zähler
In memoriam C-BIT Information-Center Hannover (2.241/1075+2.241/1076 - no longer active)
Sicherheitshinweis: Wir weisen vorsorglich darauf hin, dass wir bei der Anmeldung saemtliche automatisch uebermittelten Parameter wie IP-Adresse und/oder Einwahlrufnummer speichern, um uns und unsere Kunden vor Missbrauch zu schuetzen. Selbstverstaendlich werden wir bei Bedarf umgehend strafrechtliche Massnahmen ergreifen, um einen vorliegenden Missbrauch zu ahnden.

Correct Testing Precedence of Batch File ERRORLEVELs

Article ID:39585
Last Review:May 12, 2003
Revision:2.0
This article was previously published under Q39585

SUMMARY

When you use multiple IF ERRORLEVEL statements in batch files, the order in which the ERRORLEVELs are tested numerically is important. The correct order is descending (highest to lowest). This ordering is from the way ERRORLEVELs are tested. The IF condition is set to TRUE when the ERRORLEVEL is equal to, or greater than, the ERRORLEVEL number.

MORE INFORMATION

The following batch file fragment demonstrates this INCORRECT behavior:
   rem (execute a program which returns an errorlevel of 0 or 1)
   if errorlevel 0 goto ZERO
   if errorlevel 1 goto ONE
   goto END
   :ZERO
     echo a Zero was returned!
     goto END
   :ONE
     echo a One was returned!
   :END
				
The above example always branches to the "ZERO" label, regardless of success or failure. This example would work correctly if the ERRORLEVEL testing was made in descending order.

The CORRECT way to write such a batch file is as follows:
   rem (execute a program which returns an errorlevel of 0 or 1)
   if errorlevel 1 goto ONE
   if errorlevel 0 goto ZERO
   goto END
   :ZERO
     echo a Zero was returned!
     goto END
   :ONE
     echo a One was returned!
   :END
				

APPLIES TO
 Microsoft MS-DOS 2.11 Standard Edition
 Microsoft MS-DOS 3.1
 Microsoft MS-DOS 3.2 Standard Edition
 Microsoft MS-DOS 3.21 Standard Edition
 Microsoft MS-DOS 3.3 Standard Edition
 Microsoft MS-DOS 3.3a
 Microsoft MS-DOS 4.0 Standard Edition
 Microsoft MS-DOS 4.01 Standard Edition
 Microsoft MS-DOS 5.0 Standard Edition
 Microsoft MS-DOS 5.0a
 Microsoft MS-DOS 6.0 Standard Edition
 Microsoft MS-DOS 6.2 Standard Edition
 Microsoft MS-DOS 6.21 Standard Edition
 Microsoft MS-DOS 6.22 Standard Edition

Back to the top



This mirror is sponsored by:
Hansjoerg G. Henker
A-Z Consulting & Development
[579]

Information-Center [11.02.2012 22:52:10]