oystercatcher Posted March 17, 2005 Posted March 17, 2005 Have a short batch script to install stand alone programs that are zipped.Install directorys, program name, creation of shortcut to exe are all variablesso I can reuse the script by changing just a few lines at the top.Problem comes in when I try to run another script like this, it seems like thecmd shell environment needs to be cleaned up after each call because itlooks to me like the variables are lingering from running the previousscript causing the variables to have incorrect values. I think if I am rightabout the problem I need the call to start a new cmd shell each time. Any suggestions are appreciated. If I run the scripts one at a time no problems.@set TCLK=tclock2-inst.bat@set WROL=winroll-inst.bat@set GV63=gvim63-inst.bat@set GVRI=gvim63-reg-import.bat@set CVRC=copy-vimrc-home.bat@call %TCLK% 2>&1 >> %TEMP%\%TCLK%@call %WROL% 2>&1 >> %TEMP%\%WROL%@call %GV63% 2>&1 >> %TEMP%\%GV63%@call %GVRI% 2>&1 >> %TEMP%\%GVRI%@call %CVRC% 2>&1 >> %TEMP%\%CVRC% Here is a sample script -- @cls@echo ----------------------------------------@set SCRIPTNAME=tclock2-inst.bat@rem echo %SCRIPTNAME%@set DRV=%HOMEDRIVE%@set INFILE1=tclock2_120.zip@set TARGDIR=\tclock2_120@set TARGEXE=tclock2.exe@set SCLNK=tclock2.lnk@set M1PTH=\tool@set M1SD1PTH=%M1PTH%\system@set DRVM1SD1PTH=%DRV%%M1SD1PTH%@rem set INSTPTH=%DRVM1SD1PTH%@set INSTPTH=%DRVM1SD1PTH%%TARGDIR%@set TARGPTH=%DRVM1SD1PTH%%TARGDIR%@echo %M1SD1PTH%@echo %DRVM1SD1PTH% @echo %TARGPTH%@rem -- should not have to change anything below this line --@rem ------------------------------------------------------------@set smdir=%DRV%\Documents and Settings\All Users\Start Menu@set smpdir=%DRV%\Documents and Settings\All Users\Start Menu\Programs@set smpsudir=%smpdir%\Startup@rem echo %smdir%@rem echo %smpdir%@rem echo %smpsudir%@set M1SD1SCPTH=%smpdir%%M1SD1PTH%@set SUSCPTH=%smpsudir%@echo %M1SD1SCPTH%@echo %SUSCPTH%@set LCLSC=shortcut.exe@set LCLUNZIP=unzip.exe@rem ------------------------------------------------------------@echo ----------------------------------------@rem to test only shortcuts, use the next statement@rem goto :SHORTCUT@rem ------------------------------------------------------------@if not exist %LCLSC% ( echo Error: missing file -- %LCLSC% goto :DOSEXIT )@if not exist %LCLUNZIP% ( echo Error: missing file -- %LCLUNZIP% goto :DOSEXIT )@rem ------------------------------------------------------------@if not exist %INFILE1% ( echo Error: missing file -- %INFILE1% goto :DOSEXIT )@if not exist %INSTPTH% ( mkdir %INSTPTH% @if ERRORLEVEL 1 ( echo Error: mkdir %INSTPTH% failed goto :DOSEXIT ) )@echo copy %INFILE1% %INSTPTH%@ copy %INFILE1% %INSTPTH% @if ERRORLEVEL 1 ( echo Error: copy %INFILE1% to %INSTPTH% failed goto :DOSEXIT )@echo ----------------------------------------@echo %LCLUNZIP% -o -d %INSTPTH% %INSTPTH%\%INFILE1%@ %LCLUNZIP% -o -d %INSTPTH% %INSTPTH%\%INFILE1% @if ERRORLEVEL 1 ( echo Error: unzip %INFILE1% to %INSTPTH% failed goto :DOSEXIT )@rem to test all but shortcuts, use the next statement @rem goto :DOSEXIT@rem ------------------------------------------------------------:SHORTCUT@echo ----------------------------------------@echo %LCLSC% /F:"%M1SD1SCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%"@ %LCLSC% /F:"%M1SD1SCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%"@if ERRORLEVEL 1 ( echo Error: Shortcut failed %M1SD1SCPTH%\%SCLNK% goto :DOSEXIT )@echo ----------------------------------------@echo %LCLSC% /F:"%SUSCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%"@ %LCLSC% /F:"%SUSCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%"@if ERRORLEVEL 1 ( echo Error: Shortcut failed %SUSCPTH%\%SCLNK% goto :DOSEXIT )@rem ------------------------------------------------------------@del %INSTPTH%\%INFILE1%@if exist %INSTPTH%\%INFILE1% ( echo Error: %INSTPTH\INFILE1% del cmd failed ) @rem ------------------------------------------------------------@echo off@rem these must be the final lines in the script:DOSEXIT@echo ----------------------------------------@echo if Error: recheck -- %SCRIPTNAME%
un4given1 Posted March 17, 2005 Posted March 17, 2005 First thing you should do....@echo offput that at the top, then lose all of the other @'s
IcemanND Posted March 17, 2005 Posted March 17, 2005 Be nice put use the code tags for you posts please.2 things.1. @echo off - will prevent the lines from being displayed, saves putting an @ in froint of each line. Echo lines will displayed their associated text. edit:(dang un4given1 beat me to it)2. SetLocal & Endlocal - added to the beginning andend of the called script will make all variables in the script local to itself.@echo offset TCLK=tclock2-inst.batset WROL=winroll-inst.batset GV63=gvim63-inst.batset GVRI=gvim63-reg-import.batset CVRC=copy-vimrc-home.batcall %TCLK% 2>&1 >> %TEMP%\%TCLK%call %WROL% 2>&1 >> %TEMP%\%WROL%call %GV63% 2>&1 >> %TEMP%\%GV63%call %GVRI% 2>&1 >> %TEMP%\%GVRI%call %CVRC% 2>&1 >> %TEMP%\%CVRC%Here is a sample script --@echo offSetlocalclsecho ----------------------------------------set SCRIPTNAME=tclock2-inst.batecho %SCRIPTNAME%set DRV=%HOMEDRIVE%set INFILE1=tclock2_120.zipset TARGDIR=\tclock2_120set TARGEXE=tclock2.exeset SCLNK=tclock2.lnkset M1PTH=\toolset M1SD1PTH=%M1PTH%\systemset DRVM1SD1PTH=%DRV%%M1SD1PTH%rem set INSTPTH=%DRVM1SD1PTH%set INSTPTH=%DRVM1SD1PTH%%TARGDIR%set TARGPTH=%DRVM1SD1PTH%%TARGDIR%echo %M1SD1PTH%echo %DRVM1SD1PTH%echo %TARGPTH%rem -- should not have to change anything below this line --rem ------------------------------------------------------------set smdir=%DRV%\Documents and Settings\All Users\Start Menuset smpdir=%DRV%\Documents and Settings\All Users\Start Menu\Programsset smpsudir=%smpdir%\Startuprem echo %smdir%rem echo %smpdir%rem echo %smpsudir%set M1SD1SCPTH=%smpdir%%M1SD1PTH%set SUSCPTH=%smpsudir%echo %M1SD1SCPTH%echo %SUSCPTH%set LCLSC=shortcut.exeset LCLUNZIP=unzip.exerem ------------------------------------------------------------echo ----------------------------------------rem to test only shortcuts, use the next statementrem goto :SHORTCUTrem ------------------------------------------------------------if not exist %LCLSC% (echo Error: missing file -- %LCLSC%goto :DOSEXIT )if not exist %LCLUNZIP% (echo Error: missing file -- %LCLUNZIP%goto :DOSEXIT )rem ------------------------------------------------------------if not exist %INFILE1% (echo Error: missing file -- %INFILE1%goto :DOSEXIT )if not exist %INSTPTH% (mkdir %INSTPTH%if ERRORLEVEL 1 (echo Error: mkdir %INSTPTH% failedgoto :DOSEXIT ) )echo copy %INFILE1% %INSTPTH% copy %INFILE1% %INSTPTH%if ERRORLEVEL 1 (echo Error: copy %INFILE1% to %INSTPTH% failedgoto :DOSEXIT )echo ----------------------------------------echo %LCLUNZIP% -o -d %INSTPTH% %INSTPTH%\%INFILE1% %LCLUNZIP% -o -d %INSTPTH% %INSTPTH%\%INFILE1%if ERRORLEVEL 1 (echo Error: unzip %INFILE1% to %INSTPTH% failedgoto :DOSEXIT )rem to test all but shortcuts, use the next statementrem goto :DOSEXITrem ------------------------------------------------------------:SHORTCUTecho ----------------------------------------echo %LCLSC% /F:"%M1SD1SCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%" %LCLSC% /F:"%M1SD1SCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%"if ERRORLEVEL 1 (echo Error: Shortcut failed %M1SD1SCPTH%\%SCLNK%goto :DOSEXIT )echo ----------------------------------------echo %LCLSC% /F:"%SUSCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%" %LCLSC% /F:"%SUSCPTH%\%SCLNK%" /A:C /T:"%TARGPTH%\%TARGEXE%"if ERRORLEVEL 1 (echo Error: Shortcut failed %SUSCPTH%\%SCLNK%goto :DOSEXIT )rem ------------------------------------------------------------del %INSTPTH%\%INFILE1%if exist %INSTPTH%\%INFILE1% (echo Error: %INSTPTH\INFILE1% del cmd failed )rem ------------------------------------------------------------echo offrem these must be the final lines in the script:DOSEXITecho ----------------------------------------echo if Error: recheck -- %SCRIPTNAME%endlocal
oystercatcher Posted March 17, 2005 Author Posted March 17, 2005 Thanks for the information about SetLocal and EndLocal.Wont be able to try it right away but looks good.Also went through all the scripts with vim and cleaned up theat signs. dont remember where I learned that one.:%s/^@//g
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now