Entry 5321

Template Batch File

   

Submitted by Patrick Martin on July 27, 2010 at 11:06 p.m.
Language: Batchfile. Code size: 976 bytes.

@echo example driver script
@echo off
setlocal

:: set up a simple macro
set __OUTPUT=echo [%~n0]: 

%__OUTPUT% starting
:: delete log file
del /q %~n0.log 2>nul 

%__OUTPUT% %DATE% %TIME%
%__OUTPUT% setting environment...

call :getini

:: check for required parameter
if NOT DEFINED TEST_PROP %__OUTPUT% test property not defined & exit /b 2

%__OUTPUT% creating structure
>>%~n0.log echo doing something & set >>%~n0.txt

%__OUTPUT% exiting with error %errorlevel% 

exit /b

:: start of utility function

:getini

:: note this will set more environment variables than it knows about
:: which may be useful, but should be used judiciously

if not exist %~n0.ini %__OUTPUT% %~n0.ini missing && exit /b 2
FOR /F "eol=; delims== tokens=1,2" %%I IN (%~n0.ini) DO (
  set %%I=%%J
  )

%__OUTPUT% reporting standard variables...

:: note that  sets reports matching variables - so _SYS matchs _SYS and _SYSTEM
set TEST_PROP

goto :eof

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).