MSFN Forum: Batch file processing another batch + parameter - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch file processing another batch + parameter Rate Topic: -----

#1 User is offline   mellimik 

  • Newbie
  • Group: Members
  • Posts: 46
  • Joined: 04-November 06

Posted 13 November 2006 - 02:00 PM

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?


#2 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,249
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 13 November 2006 - 03:41 PM

I hate to tell you but it works fine for me the way it is written, except that %2 is passed as %2"

#3 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 13 November 2006 - 10:26 PM

Why use the START command, the CALL command should return to the originating batch only upon completion.

#4 User is offline   mellimik 

  • Newbie
  • Group: Members
  • Posts: 46
  • Joined: 04-November 06

Posted 14 November 2006 - 01:09 AM

View PostIcemanND, on Nov 13 2006, 10:41 PM, said:

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:

View PostYzöwl, on Nov 14 2006, 05:26 AM, said:

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

#5 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,439
  • Joined: 13-January 06

Posted 14 November 2006 - 01:54 AM

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


#6 User is offline   mellimik 

  • Newbie
  • Group: Members
  • Posts: 46
  • Joined: 04-November 06

Posted 14 November 2006 - 05:49 AM

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)

This post has been edited by mellimik: 14 November 2006 - 05:50 AM


#7 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 14 November 2006 - 08:07 AM

View Postmellimik, on Nov 14 2006, 07:09 AM, said:

View PostYzöwl, on Nov 14 2006, 05:26 AM, said:

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 


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy