Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-blocking batch file execution

Tags:

batch-file

I have the following commands in a batch file:

"C:\MI2\Stream\bin\Debug\Stream.exe" 19
"C:\MI2\Stream\bin\Debug\Stream.exe" 20
"C:\MI2\Stream\bin\Debug\Stream.exe" 21
"C:\MI2\Stream\bin\Debug\Stream.exe" 23
"C:\MI2\Stream\bin\Debug\Stream.exe" 25

I'm attempting to execute 5 instances of an application I created, passing in a different param to each. My goal is that when I run this batch file, it launches the 5 instances of this app, loading a UI component for each. Eventually I will make this more elegant, and put a wrapper app around this, but for now i just want these to run simultaneously.

The problem is, when I launch this batch file, it executes the first line, loading the UI. That's it. It doesn't move on to the second line. Thoughts?

Edit to Add - I could certainly do this from separate batch files, but I'd like to have one-click launching. Scott

like image 524
Scott Silvi Avatar asked Sep 03 '11 19:09

Scott Silvi


People also ask

How do you make a batch file that does not close automatically?

If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.

What does 0 |% 0 Do in batch?

What does 0 |% 0 Do in batch? %0|%0 is a fork bomb. It will spawn another process using a pipe | which runs a copy of the same program asynchronously. This hogs the CPU and memory, slowing down the system to a near-halt (or even crash the system).

What is %% A in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


1 Answers

You can use start:

start "" "C:\MI2\Stream\bin\Debug\Stream.exe" 19
start "" "C:\MI2\Stream\bin\Debug\Stream.exe" 20
start "" "C:\MI2\Stream\bin\Debug\Stream.exe" 21
start "" "C:\MI2\Stream\bin\Debug\Stream.exe" 23
start "" "C:\MI2\Stream\bin\Debug\Stream.exe" 25

The first argument is the title of the created command line window, which we don't care about, so it can be left empty.

Even better would be to use for:

forr %i in (19, 20, 21, 23, 25) do start "" "C:\MI2\Stream\bin\Debug\Stream.exe" %i
like image 94
svick Avatar answered Sep 20 '22 16:09

svick