jamesw
Member
Registered: 28th Jun 02
Location: Station Town, County Durham
User status: Offline
|
Ive got a big ass batch file I nocked up to use at work - basically just a menu system that uses varibles to launch different commands and run different fixes, my question is what on earth is the difference between using "errorlevel" and the varible %errorlevel% - i thought they were the same?! obviously not
Example
find supposed to give exit code 0 if it finds a match, and exit code 1 if the search runs but it cant find a match - but try the below it dont work out
echo completed | find "failed"
if errorlevel 0 echo match found
the above for some reason will trigger the errorlevel 0 command
so why on earth is it picking up errorlevel 0???
where as the below works fine as expected
echo completed | find "failed"
if %errorlevel%==0 echo match found
Its not a problem, i can just use the varible, just curious
[Edited on 07-03-2008 by jamesw]
[Edited on 07-03-2008 by jamesw]
|
jamesw
Member
Registered: 28th Jun 02
Location: Station Town, County Durham
User status: Offline
|
Found my answer
ERRORLEVEL nnn (v2.0 Win95 NT3.1)
Specifies a true condition only if the previous program run by COMMAND.COM returned an exit code equal to or greater than number.
ERRORLEVEL statements must listed in DECREASING order. The operating system will consider the IF statement true if the ERRORLEVEL is greater than or equal to the values specified, see the CHOICE examples.
Normal completion of a command will return ERRORLEVEL=0.
|