Batch Script to execute multiple arguments at same time

I have a batch script named env_setup.bat which takes in multiple arguments such as server02, server05, server06 etc..

A typical calling example of the batch script would be something like

env_setup.bat  server04  server02 server05 

Open in new window



In the batch script I loop through the arguments ( various servers) and setup variables(using property files or other hard-coded variables)  for that servers and execute a command( either sql file or robocopy  or some other commands)

 This batch script usually takes 15 minutes to run for each server.  Some times I would need to pass in arguments  for  5 or 6 servers which takes long time.

 is there a way I can ask pass in arguments to a wrapper script so that env_setup.bat is run simultaneously for several servers and it executes in 15 minutes rather than 15 x n(where n is number of servers).

there is no dependency between arguments,  i.e all of them can be run simulataneously.


env_setup.bat server01
env_setup.bat server02
etc..

This batch script will be called by another script and arguments(servers) passed dynamically.


I hope that makes sense.
maverickxxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne88Commented:
Try using the START command, should run all simulatenously

start env_setup.bat server01
start env_setup.bat server02
start env_setup.bat server03
Lee W, MVPTechnology and Business Process AdvisorCommented:
The key is START as Wayne88 suggests.

You could either create another batch file that launches env_setup.bat for each server or run them manually for each server as illustrated by wayne:

@echo off

REM Start of the loop to be done for each server specified on the command line
:StartSequence

REM Enter your code here - for demo, this script only echos back each parameter specified on the command line
Echo %1
REM But for example:
START ENV_SETUP.BAT %1

REM Shift moves to the next command line parameter specified thus no limit to the count
SHIFT

REM If the next command line parameter is empty then exit the batch script.
If ""=="%1" Goto End

REM The above Goto would have kicked in if we were done; we're not so repeat the command.
Goto StartSequence
:End

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.