134

How to run multiple dos commands?

I have a for loop, which runs detection of server to detect which server works and is fast. And because there is more servers, I wish not to run all server detections in sequence, but in parallel.

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
John Boe
  • 3,501
  • 10
  • 37
  • 71
  • Look here: http://stackoverflow.com/questions/672719/parallel-execution-of-shell-processes – Anton Skovorodko Jun 13 '12 at 08:30
  • possible duplicate of [How do I run a bat file in the background from another bat file?](http://stackoverflow.com/questions/649634/how-do-i-run-a-bat-file-in-the-background-from-another-bat-file) – John Conde Jun 13 '12 at 18:11
  • 2
    This one is a complete script using only windows batch features: http://stackoverflow.com/a/11715437/2026975 – imriss Aug 16 '13 at 19:38
  • [Windows cmd is **not** DOS](https://superuser.com/q/451432/241386). There are no such things like for loop or parallel in DOS – phuclv Jul 20 '17 at 02:47

4 Answers4

239

You can execute commands in parallel with start like this:

start "" ping myserver
start "" nslookup myserver
start "" morecommands

They will each start in their own command prompt and allow you to run multiple commands at the same time from one batch file.

starball
  • 20,030
  • 7
  • 43
  • 238
Bali C
  • 30,582
  • 35
  • 123
  • 152
7

I suggest you to see "How do I run a bat file in the background from another bat file?"

Also, good answer (of using start command) was given in "Parallel execution of shell processes" question page here;

But my recommendation is to use PowerShell. I believe it will perfectly suit your needs.

Community
  • 1
  • 1
Sergei Danielian
  • 4,938
  • 4
  • 36
  • 58
7

You can execute commands in parallel with start command, like:

start "" ping google.com

But to execute WITHOUT new window, use the /b option, like:

start /b ping google.com -t
start /b ping example.com -t

Moreover, the -t option makes ping repeat infinite times.

Also, try Ctrl + Break if Ctrl + C does not work (but Ctrl+C works for above example).

Top-Master
  • 7,611
  • 5
  • 39
  • 71
4

if you have multiple parameters use the syntax as below. I have a bat file with script as below:

start "dummyTitle" [/options] D:\path\ProgramName.exe Param1 Param2 Param3 
start "dummyTitle" [/options] D:\path\ProgramName.exe Param4 Param5 Param6 

This will open multiple consoles.

nstenz
  • 117
  • 1
  • 5
Mohit Kanojia
  • 690
  • 5
  • 6