217

Say, if I have

  • foo.exe
  • bar.exe
  • baz.exe

How do I run all of them from a batch file asynchronously, i.e. without waiting for the previous program to stop?

7 Answers 7

289

Using the START command to run each program should get you what you need:

START "title" [/D path] [options] "command" [parameters]

Every START invocation runs the command given in its parameter and returns immediately, unless executed with a /WAIT switch.

That applies to command-line apps. Apps without command line return immediately anyway, so to be sure, if you want to run all asynchronously, use START.

Sign up to request clarification or add additional context in comments.

4 Comments

Okay, thanks. I should have read each entry of help carefully. :)
Shameless self-advertising: I once created a batch which is able to function as some kind of thread pool, just for processes: stackoverflow.com/questions/672719/…
If you need to provide arguments or if the path to the commands contains spaces remember to add quotes. In this case you also need to provide a title for the opening console window: start "" "[path to command]" [command args]
"Apps without command line return immediately anyway" – Are you sure? Why GUI application blocks a batch file?
76

Combining a couple of the previous answers, you could try start /b cmd /c foo.exe.

For a trivial example, if you wanted to print out the versions of java/groovy/grails/gradle, you could do this in a batch file:

@start /b cmd /c java -version
@start /b cmd /c gradle -version
@start /b cmd /c groovy -version
@start /b cmd /c grails -version

If you have something like Process Explorer (Sysinternals), you will see a few child cmd.exe processes each with a java process (as per the above commands). The output will print to the screen in whatever order they finish.

start /b :  Start application without creating a new window. The
             application has ^C handling ignored. Unless the application
             enables ^C processing, ^Break is the only way to interrupt
             the application

cmd /c : Carries out the command specified by string and then terminates

2 Comments

it prevents the command from being echoed to the console. In batch scripts, sometimes you'll see echo off at the beginning which, when you execute the script, will prevent all the commands from being echoed to the console. The @ is similar but just for that single command. So, sometimes you'll see @echo off.
Did not work for me. Still stopped waiting for the application to close before it moved on.
41

You can use the start command to spawn background processes without launching new windows:

start /b foo.exe

The new process will not be interruptable with CTRL-C; you can kill it only with CTRL-BREAK (or by closing the window, or via Task Manager.)

4 Comments

Where is BREAK on keyboards these days?
@user2023370 Still on the Pause key. Most laptops that lack certain keys support hidden key combinations.
Did not work for me. Still stopped waiting for the application to close before it moved on.
26

Create a batch file with the following lines:

start foo.exe
start bar.exe
start baz.exe 

The start command runs your command in a new window, so all 3 commands would run asynchronously.

1 Comment

works as long as you don't have a path with spaces.. Then when you put double quotes around it, it thinks in a title, not an application. This works. START "VMPlayer" /D "C:\Users\gavin\Virtual Machines\CentOS 8 64-bit" "C:\Program Files (x86)\VMware\VMware Player\vmplayer.exe"
19

Use the START command:

start [programPath]

If the path to the program contains spaces remember to add quotes. In this case you also need to provide a title for the opening console window

start "[title]" "[program path]"

If you need to provide arguments append them at the end (outside the command quotes)

start "[title]" "[program path]" [list of command args]

Use the /b option to avoid opening a new console window (but in that case you cannot interrupt the application using CTRL-C

Comments

11

There's a third (and potentially much easier) option. If you want to spin up multiple instances of a single program, using a Unix-style command processor like Xargs or GNU Parallel can make that a fairly straightforward process.

There's a win32 Xargs clone called PPX2 that makes this fairly straightforward.

For instance, if you wanted to transcode a directory of video files, you could run the command:

dir /b *.mpg |ppx2 -P 4 -I {} -L 1 ffmpeg.exe -i "{}" -quality:v 1 "{}.mp4"

Picking this apart, dir /b *.mpg grabs a list of .mpg files in my current directory, the | operator pipes this list into ppx2, which then builds a series of commands to be executed in parallel; 4 at a time, as specified here by the -P 4 operator. The -L 1 operator tells ppx2 to only send one line of our directory listing to ffmpeg at a time.

After that, you just write your command line (ffmpeg.exe -i "{}" -quality:v 1 "{}.mp4"), and {} gets automatically substituted for each line of your directory listing.

It's not universally applicable to every case, but is a whole lot easier than using the batch file workarounds detailed above. Of course, if you're not dealing with a list of files, you could also pipe the contents of a textfile or any other program into the input of pxx2.

3 Comments

The latest xargs win32 port works well nowadays (the one included with git for windows anyway).
This is great except it fails dealing with files containing unicode characters. Any plans to support unicode files? Thanks.
@GökhanSever In the past I've worked around this issue by using the "short name" form of the path, that looks like C:\PROGRA~1\WINDOW~3\MYPROG~1.EXE. Not pretty, but it works.
0

I could not get anything to work I ended up just using powershell to start bat scripts .. sometimes even start cmd /c does not work not sure why .. I even tried stuff like start cmd /c notepad & exit

start-Process "c:\BACKUP\PRIVATE\MobaXterm_Portable\MobaXterm_Portable.bat" -WindowStyle Hidden

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.