Skip to content

Instantly share code, notes, and snippets.

@jetstreamin
Created July 10, 2015 16:37
Show Gist options
  • Save jetstreamin/f12c9378fd7d14427a2a to your computer and use it in GitHub Desktop.
Save jetstreamin/f12c9378fd7d14427a2a to your computer and use it in GitHub Desktop.
REM Exmaple DOS batch template file
@echo off
echo My message
REM Check passed parameters are correct
set _argcActual=0
set _argcExpected=3
for %%i in (%*) do set /A _argcActual+=1
if %_argcActual% NEQ %_argcExpected% GOTO WrongArgs
REM Does a file exist?
IF NOT EXIST %3\my.exe GOTO CantFindExe
REM Do something and check return code
%3\my.exe %1 %2
ECHO %ERRORLEVEL%
IF %ERRORLEVEL% NEQ 0 GOTO NonZeroErrorLevel
REM Everything is fine so exit normally
Goto End
:WrongArgs
ECHO Incorrect arguments. Args: xxx yyyy exe_path
exit /b 1
:CantFindEXE
ECHO Cant find %3\my.exe
exit /b 2
:NonZeroErrorLevel
ECHO Exit code was non zero
exit /b 3
:End
ECHO Done.
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment