• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4031
  • Last Modified:

Execute multiple .bat files at same time

Hi,

I have 17 .bat files.  I want to fire them off at same time.  Is that possible within another script?
0
elwayisgod
Asked:
elwayisgod
  • 5
  • 4
  • 3
  • +1
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
any language which supports parallelism can do this job like .net/java etc
0
 
KingofthecartsCommented:
Use the call command,

I think in CMD if you use:

call batch.bat ""  <- Leave that double quote there.
0
 
Meir RivkinFull stack Software EngineerCommented:
You can also execute parallel jobs in Powershell 2 using Background Jobs.
check here:
Can Powershell Run Commands in Parallel?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Meir RivkinFull stack Software EngineerCommented:
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
 
KingofthecartsCommented:
Wish I had time to get into Powershell :S Looks fun :D
0
 
Meir RivkinFull stack Software EngineerCommented:
go for it :)
0
 
KingofthecartsCommented:
Got a good any resource sites to get started?
0
 
Meir RivkinFull stack Software EngineerCommented:
download the free and amazing powergui editor: powergui

and here you can find tutorials and example codes:
http://powergui.org/index.jspa
0
 
KingofthecartsCommented:
OOO, love it.

Thanks Alot!
0
 
Steve KnightIT ConsultancyCommented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
elwayisgodAuthor Commented:
Can't do powershell or any freeware.  'start' instead of 'call' was perfect.
0
 
Steve KnightIT ConsultancyCommented:
no problem, glad it helped.  btw if you add /min it will run them minimised if you prefer.

steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now