Solved

Execute multiple .bat files at same time

Posted on 2013-01-29
13
1,697 Views
Last Modified: 2013-01-30
Hi,

I have 17 .bat files.  I want to fire them off at same time.  Is that possible within another script?
0
Comment
Question by:elwayisgod
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38831516
any language which supports parallelism can do this job like .net/java etc
0
 
LVL 1

Expert Comment

by:Kingofthecarts
ID: 38831518
Use the call command,

I think in CMD if you use:

call batch.bat ""  <- Leave that double quote there.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38831521
You can also execute parallel jobs in Powershell 2 using Background Jobs.
check here:
Can Powershell Run Commands in Parallel?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38831533
put your 17 batch files path in a file (batchlist.txt), one in each line and run the following powershell code:
Get-Content "batchlist.txt" | %{

  # Define what each job does
  $ScriptBlock = {
    $_ #run the batch file
    Start-Sleep 60
  }

  # Execute the jobs in parallel
  Start-Job $ScriptBlock
}

Get-Job

# Wait for it all to complete
While (Get-Job -State "Running")
{
  Start-Sleep 10
}

# Getting the information back from the jobs
Get-Job | Receive-Job

Open in new window

0
 
LVL 1

Expert Comment

by:Kingofthecarts
ID: 38831544
Wish I had time to get into Powershell :S Looks fun :D
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38831555
go for it :)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:Kingofthecarts
ID: 38831562
Got a good any resource sites to get started?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38831574
download the free and amazing powergui editor: powergui

and here you can find tutorials and example codes:
http://powergui.org/index.jspa
0
 
LVL 1

Expert Comment

by:Kingofthecarts
ID: 38831579
OOO, love it.

Thanks Alot!
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 38831691
Just create a batch file.... either run them manually in there with:


@echo off
START "BATCH1" "c:\myfolder\mybatch1.cmd"
START "BATCH2" "c:\myfolder\mybatch2.cmd"

etc.

or using a subroutine if they are all in the same dir etc.

@echo off
cd /d c:\maindir
call :runbatch BATCH1.cmd
call :runbatch BATCH2.cmd
call :runbatch c:\someotherdir\BATCH3.cmd
exit /b
:runbatch
  START "%~*" "%~*"
exit /b

Or read the names and run all in a dir...  can get fancier telling it to leave out own name etc. if needed


@Echo off
cd /d c:\batchdir
for %%a in (*.cmd) do START "%%~a" "%%~a"

hth

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38831699
The first bit in quotes on the START command is just the title of the window, second parameter is the filename to run.  Unless you add /WAIT it carries on to the next command with the batch launched in another window.

Steve
0
 

Author Closing Comment

by:elwayisgod
ID: 38836794
Can't do powershell or any freeware.  'start' instead of 'call' was perfect.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38837028
no problem, glad it helped.  btw if you add /min it will run them minimised if you prefer.

steve
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now