:
So u see, I have use errorlevel without enclosing it with % % and have
branched the result based on If errorlevel not 0 for the ping command,
yet for the reg query I had to use %errorlevel% and grt 0 to branch
out!! I do not understand, but it works. If anybody can explain the
reason for the difference, I wld appreciate it. However, Thanks Austin
again for your help.
David.
Hello David,
see the help "if /?"
IF [NOT] ERRORLEVEL
is the old compatible way dealing with errorlevel in a descending manner.
To overcome that fuss the errorlevel is copied to the environment var
%ERRORLEVEL%. You may compare the value and even construct labels with
it. You can echo it directly without knowing the range.
See this example batch.
01. ::RetErrLvl.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
02. @echo off & setlocal
03. :: Generating and checking Errlorlevels 1 to 16
04.
05. :: Using Variable %ERRORLEVEL% for every possible value
06. for /L %%A in (1,1,16) do (
07. Call :RetErrLvl %%A
08. call echo Errorlevel %%ERRORLEVEL%%
09. )
10.
11. :: Using old dos compatible method of descending numbers
12. :: only for the numbers up to 16.
13. :: The usage of goto inside for loops is unreliable.
14. :Loop
15. set /A ErrLvl+=1
16. call :RetErrLvl %ErrLvl%
17. if ERRORLEVEL 16 echo ERRORLEVEL 16 & goto Label
18. if ERRORLEVEL 15 echo ERRORLEVEL 15 & goto Label
19. if ERRORLEVEL 14 echo ERRORLEVEL 14 & goto Label
20. if ERRORLEVEL 13 echo ERRORLEVEL 13 & goto Label
21. if ERRORLEVEL 12 echo ERRORLEVEL 12 & goto Label
22. if ERRORLEVEL 11 echo ERRORLEVEL 11 & goto Label
23. if ERRORLEVEL 10 echo ERRORLEVEL 10 & goto Label
24. if ERRORLEVEL 9 echo ERRORLEVEL 9 & goto Label
25. if ERRORLEVEL 8 echo ERRORLEVEL 8 & goto Label
26. if ERRORLEVEL 7 echo ERRORLEVEL 7 & goto Label
27. if ERRORLEVEL 6 echo ERRORLEVEL 6 & goto Label
28. if ERRORLEVEL 5 echo ERRORLEVEL 5 & goto Label
29. if ERRORLEVEL 4 echo ERRORLEVEL 4 & goto Label
30. if ERRORLEVEL 3 echo ERRORLEVEL 3 & goto Label
31. if ERRORLEVEL 2 echo ERRORLEVEL 2 & goto Label
32. if ERRORLEVEL 1 echo ERRORLEVEL 1 & goto Label
33. if ERRORLEVEL 0 echo ERRORLEVEL 0 & goto Label
34. :Label
35. if %ErrLvl% LSS 16 goto :Loop
36.
37. goto :EOF
38. :RetErrLvl
39. exit /b %1
40. ::RetErrLvl.cmd:::::::::::::::::::::::::::::::::::::::::::::::::
The resulting output is very similar, the expenditure not.:::