DOS Batch example template


/ Published in: DOS Batch
Save to your folder(s)

An exmaple DOS batch file


Copy this code and paste it in your HTML
  1. REM Exmaple DOS batch template file
  2. @echo off
  3. echo My message
  4.  
  5. REM Check passed parameters are correct
  6. set _argcActual=0
  7. set _argcExpected=3
  8. for %%i in (%*) do set /A _argcActual+=1
  9. if %_argcActual% NEQ %_argcExpected% GOTO WrongArgs
  10.  
  11.  
  12. REM Does a file exist?
  13. IF NOT EXIST %3\my.exe GOTO CantFindExe
  14.  
  15. REM Do something and check return code
  16. %3\my.exe %1 %2
  17. ECHO %ERRORLEVEL%
  18. IF %ERRORLEVEL% NEQ 0 GOTO NonZeroErrorLevel
  19.  
  20.  
  21. REM Everything is fine so exit normally
  22. Goto End
  23.  
  24.  
  25. :WrongArgs
  26. ECHO Incorrect arguments. Args: xxx yyyy exe_path
  27. exit /b 1
  28.  
  29.  
  30. :CantFindEXE
  31. ECHO Cant find %3\my.exe
  32. exit /b 2
  33.  
  34. :NonZeroErrorLevel
  35. ECHO Exit code was non zero
  36. exit /b 3
  37.  
  38. :End
  39. ECHO Done.
  40. exit /b 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.