Return to Snippet

Revision: 59569
at September 18, 2012 19:10 by imbraz


Initial Code
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

Initial URL


Initial Description
An exmaple DOS batch  file

Initial Title
DOS Batch example template

Initial Tags


Initial Language
DOS Batch