mellimik Posted November 13, 2006 Posted November 13, 2006 We have a little problem with our batch file. It is used as an automated installer, its functions are to go through four predefined folders and try to run install.cmd files. For some reason i am unable to make this file to pass a parameter for those install.cmd files it launches.:: AUTOMATIC BATCH INSTALLERIF /I :%COMPUTERNAME%==:RISSERVER ECHO "Do not run from Server!!!" && PAUSE && EXITFOR /D %%i IN (%~dp0Global\Mandatory\*) DO start "Installing %%~nxi" /wait /D"%%i" "CMD /C EXIT | %%~si\install.cmd %2" FOR /D %%i IN (%~dp0Private\Mandatory\*) DO start "Installing %%~nxi" /wait /D"%%i" "CMD /C EXIT | %%~si\install.cmd %2" IF /I :exception==:%1 ( REM Nothing to do here) ELSE ( FOR /D %%i IN (%~dp0Global\optional\*) DO start "Installing %%~nxi" /wait /D"%%i" "CMD /C EXIT | %%~si\install.cmd %2" FOR /D %%i IN (%~dp0Private\optional\*) DO start "Installing %%~nxi" /wait /D"%%i" "CMD /C EXIT | %%~si\install.cmd %2" )So that %2 (passed parameter #2) should be passed along to all of those install.cmd files it founds. For some reason this does not work. Install.cmd files never receive this parameter.Has anyone of you got any improvement suggestions?
IcemanND Posted November 13, 2006 Posted November 13, 2006 I hate to tell you but it works fine for me the way it is written, except that %2 is passed as %2"
Yzöwl Posted November 14, 2006 Posted November 14, 2006 Why use the START command, the CALL command should return to the originating batch only upon completion.
mellimik Posted November 14, 2006 Author Posted November 14, 2006 I hate to tell you but it works fine for me the way it is written, except that %2 is passed as %2"Are you sure? My install.cmd files don't receive %2 parameter.You can try to re-create my folder structure:.Global..Mandatory...EncryptionSoft...AntivirusSoft..Optional...VPNClient...AdobeReader.Private..Mandatory..OptionalAnd place these folders along with the start.cmd file to somewhere. Then create install.cmd file to, let's say, inside VPNClient folder and make it to echo parameters it receives from start.cmd. Ofcourse you have to start start.cmd with two parameters.I just don't get it, why it doesn't work. Sniff Why use the START command, the CALL command should return to the originating batch only upon completion.Because the START command gives me the option to use /D as in "Start path for this batch file is this directory". CALL runs a batch file in the context of the calling batch file, meaning you don't have the option to modify start path which is the only important point here
allen2 Posted November 14, 2006 Posted November 14, 2006 I'll rewrite your script like this:IF /I "%COMPUTERNAME%"=="RISSERVER" ECHO "Do not run from Server!!!" && PAUSE && EXITFOR /D %%i IN (%~dp0Global\Mandatory\*) DO (start "Installing %%~nxi" /wait /D "%%i" "CMD /C %%~si\install.cmd %2" )FOR /D %%i IN (%~dp0Private\Mandatory\*) DO (start "Installing %%~nxi" /wait /D "%%i" "CMD /C %%~si\install.cmd %2" )IF /I "exception"=="%1" ( REM Nothing to do here) ELSE ( FOR /D %%i IN (%~dp0Global\optional\*) DO (start "Installing %%~nxi" /wait /D "%%i" "CMD /C %%~si\install.cmd %2" ) FOR /D %%i IN (%~dp0Private\optional\*) DO (start "Installing %%~nxi" /wait /D "%%i" "CMD /C %%~si\install.cmd %2" ))
mellimik Posted November 14, 2006 Author Posted November 14, 2006 (edited) It works like i have it below. Thanks for everyone of helping!FOR /D %%i IN (%~dp0Private\optional\*) DO (start "Installing %%~nxi" /wait /D "%%i" CMD /C %%~si\install.cmd %2) Edited November 14, 2006 by mellimik
Yzöwl Posted November 14, 2006 Posted November 14, 2006 Why use the START command, the CALL command should return to the originating batch only upon completion.Because the START command gives me the option to use /D as in "Start path for this batch file is this directory". CALL runs a batch file in the context of the calling batch file, meaning you don't have the option to modify start path which is the only important point here Well I suppose that depends how you code your batch file!example - (untested)@ECHO OFF &SETLOCAL ENABLEEXTENSIONSSET "PNT=GLOBAL PRIVATE"SET "CLD=MANDATORY"IF /I "%~1" NEQ "EXCEPTION" (SET CLD=%CLD% OPTIONAL)FOR %%? IN (%PNT%) DO (CALL :SUB %%?\ %2)ENDLOCAL &GOTO :EOF:SUBFOR %%? IN (%CLD%) DO (CALL :DOIT %1%%?\ %2)GOTO :EOF:DOITFOR /D %%? IN (%1*) DO (IF EXIST "%%?\INSTALL.CMD" ( PUSHD %%? &&CALL INSTALL %2 &&POPD))GOTO :EOF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now