Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for errlevel.bat

(view source code of errlevel.bat as plain text)

  1. @ECHO OFF
  2. REM Reset variables
  3. FOR %%A IN (1 10 100) DO SET ERR%%A=
  4.  
  5. REM Check error level hundredfolds
  6. FOR %%A IN (0 1 2) DO IF ERRORLEVEL %%A00 SET ERR100=%%A
  7. IF %ERR100%==2 GOTO 200
  8. IF %ERR100%==0 IF NOT "%1"=="/0" SET ERR100=
  9.  
  10. REM Check error level tenfolds
  11. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL %ERR100%%%A0 SET ERR10=%%A
  12. IF "%ERR100%"=="" IF %ERR10%==0 SET ERR10=
  13.  
  14. :1
  15. REM Check error level units
  16. FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL %ERR100%%ERR10%%%A SET ERR1=%%A
  17. REM Modification necessary for errorlevels 250+
  18. IF NOT ERRORLEVEL 250 FOR %%A IN (6 7 8 9) DO IF ERRORLEVEL %ERR100%%ERR10%%%A SET ERR1=%%A
  19. GOTO End
  20.  
  21. :200
  22. REM In case of error levels over 200 both
  23. REM tenfolds and units are limited to 5
  24. REM since the highest DOS error level is 255
  25. FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL 2%%A0 SET ERR10=%%A
  26. IF ERR10==5 FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL 25%%A SET ERR1=%%A
  27. IF NOT ERR10==5 GOTO 1
  28.  
  29. :End
  30. REM Clean up the mess and show results
  31. SET ERRORLEV=%ERR100%%ERR10%%ERR1%
  32. FOR %%A IN (1 10 100) DO SET ERR%%A=
  33. ECHO ERRORLEVEL  %ERRORLEV%
  34.  

page last uploaded: 2017-07-06, 12:37