Immagine how exciting it must have been for Peter "batchwizard" Gibbons* to take over development and support for his company's "software distribution, configuration management, and auditing" system. Afterall, it would seem to be an excellent opportunity to learn more about Microsoft SMS, and how it's used and expanded upon in a large organization. Now, just try immagine how quickly excitement turned into dissapointment when Peter learned that the entire system was developed in Windows batch code. In over sixty-five command files.

:: ED: note the use of flag files to maintain state across 
:: different batch files
@echo off ::cls :: ***************************************** :: ***** DO NOT EDIT THIS FILE ***** :: ***************************************** :: THIS CMD FILE IS RESERVED FOR USE BY INITECH INDUSTRIES. set command=%1 set command=%command:/=^% for /F "delims=/" %%a in (%command%) do set command=%%a set command=%command:^=/% set outputline=%2 set outputline=%outputline:/=^% for /F "delims=/" %%a in (%outputline%) do set outputline=%%a set outputline=%outputline:^=/% for /F "delims=/" %%a in (%3) do set tag=%%a for /F "delims=/" %%a in (%4) do set header=%%a for /F "delims=/" %%a in (%5) do set left=%%a for /F "delims=/" %%a in (%6) do set length=%%a if /I "%7"=="Q" set ScreenUpdate=Q if /I "%7"=="QX" set ScreenUpdate=QX if /I "%7"=="S" set ScreenUpdate=S if "%command%"=="" goto end set result= set data= if NOT "%PrevCommand%"=="%command%" goto issuecommand if exist %BCTEMP%\~ADT729.tmp goto process if exist %BCTEMP%\~ADT728.tmp goto process :issuecommand %command% >%BCTEMP%\~ADT729.tmp 2>%BCTEMP%\~ADT728.tmp dir "%BCTEMP%\~ADT729.tmp" > "%BCTEMP%\~ADT604.tmp" find /I "~ADT729.tmp" < "%BCTEMP%\~ADT604.tmp" > "%BCTEMP%\~ADT605.tmp" find /I " 0 " < "%BCTEMP%\~ADT605.tmp" >NUL 2>NUL if ERRORLEVEL 2 goto end if ERRORLEVEL 1 goto process if ERRORLEVEL 0 goto checkerror goto end :checkerror if not exist %BCTEMP%\~ADT728.tmp set result=No Command output&& goto WriteToFile dir "%BCTEMP%\~ADT728.tmp" > "%BCTEMP%\~ADT606.tmp" find /I "~ADT728.tmp" < "%BCTEMP%\~ADT606.tmp" > "%BCTEMP%\~ADT607.tmp" find /I " 0 " < "%BCTEMP%\~ADT607.tmp" >NUL 2>NUL if ERRORLEVEL 2 goto end if ERRORLEVEL 1 goto processerror if ERRORLEVEL 0 set result=No Command output&& goto WriteToFile goto end :processerror find /I %2 "%BCTEMP%\~ADT728.tmp" > "%BCTEMP%\~" if ERRORLEVEL 2 goto notfound if ERRORLEVEL 1 goto notfound if ERRORLEVEL 0 goto process2 goto end :process find /I %2 "%BCTEMP%\~ADT729.tmp" > "%BCTEMP%\~" if ERRORLEVEL 2 goto notfound if ERRORLEVEL 1 goto notfound if ERRORLEVEL 0 goto process2 goto end :notfound set result=Item not found goto WriteToFile :process2 for /F "tokens=1* delims=~" %%a in (%BCTEMP%\~) do SET result=%%a :Left [ED: And who said string manipulation was not possible in BATCH?] if %4=="" goto endLeft if %4=="0" goto endLeft if %left% EQU 1 set result=%result:~1%&& goto endLeft if %left% EQU 2 set result=%result:~2%&& goto endLeft if %left% EQU 3 set result=%result:~3%&& goto endLeft :: ED - Snip 4-76 if %left% EQU 77 set result=%result:~77%&& goto endLeft if %left% EQU 78 set result=%result:~78%&& goto endLeft if %left% EQU 79 set result=%result:~79%&& goto endLeft if %left% EQU 80 set result=%result:~80%&& goto endLeft :endLeft :Length if %5=="" goto endLength if %5=="full" goto endLength if %length% EQU 1 set result=%result:~,1%&& goto endLength if %length% EQU 2 set result=%result:~,2%&& goto endLength if %length% EQU 3 set result=%result:~,3%&& goto endLength :: ED - Snip if %length% EQU 77 set result=%result:~,77%&& goto endLength if %length% EQU 78 set result=%result:~,78%&& goto endLength if %length% EQU 79 set result=%result:~,79%&& goto endLength if %length% EQU 80 set result=%result:~,80%&& goto endLength :endLength if not "%tag:~,1%"==" " set result=%tag% :WriteToFile if "%header:~,1%"==" " set header=%outputline% if "%result%"=="" set result=- echo %AuditorSet% - %header% - %result% >> %LML%\Auditor\results\%AuditorSet%-outputs.chk set PrevCommand=%command% if /I "%ScreenUpdate%"=="S" goto end if /I "%ScreenUpdate%"=="QX" goto end if "%AuditorSet%"=="" goto endsetvars if /I not "%AuditorSet:~0,8%"=="_system_" set AuditorHEADER=%AuditorHEADER%,%AuditorSet%:%header% if /I "%AuditorSet:~0,8%"=="_system_" set AuditorHEADER=%AuditorHEADER%,%AuditorSet:~8%:%header% set result=%result:,=.% set AuditorDATA=%AuditorDATA%,%result% :endsetvars if /I "%ScreenUpdate%"=="Q" goto end echo %header% - %result% :end set data=%result% set outputline= set command= set result= set left= set length= set tag= set header=

And one other, delfile.cmd, which deletes a file based on the presense of a flag file ...

@echo off
::cls

:: *****************************************
:: *****     DO NOT EDIT THIS FILE     *****
:: *****************************************

:: THIS CMD FILE IS RESERVED FOR USE BY INITECH INDUSTRIES.

if "%2"=="" goto end

:: Remove the Actual File
set DELFILE=%2
set DELFILE=%DELFILE:delete-=%

if not exist %1%DELFILE% goto endRemoveActualFile
echo DELFILE: Deleting the %DELFILE% file from the %1 folder >> %LML%\system\log.txt
del %1%DELFILE% /f /q >NUL 2>NUL
:endRemoveActualFile

:: Remove the Delete File
if not exist %1%2 goto endRemoveDeleteFile
del %1%2 /f /q >NUL 2>NUL
:endRemoveDeleteFile

:end

* For the Office Space [imdb.com] impaired, names change to protect the innocent

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!