Jump to content

Recommended Posts

Posted

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 INSTALLER

IF /I :%COMPUTERNAME%==:RISSERVER ECHO "Do not run from Server!!!" && PAUSE && EXIT

FOR /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?


Posted
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

..Optional

And 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 :blink:

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 :)

Posted

I'll rewrite your script like this:

IF /I "%COMPUTERNAME%"=="RISSERVER" ECHO "Do not run from Server!!!" && PAUSE && EXIT

FOR /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" )
)

Posted (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 by mellimik
Posted
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 ENABLEEXTENSIONS
SET "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
:SUB
FOR %%? IN (%CLD%) DO (CALL :DOIT %1%%?\ %2)
GOTO :EOF
:DOIT
FOR /D %%? IN (%1*) DO (IF EXIST "%%?\INSTALL.CMD" (
PUSHD %%? &&CALL INSTALL %2 &&POPD))
GOTO :EOF

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...