0

i have 3 commands to run in Windows terminal, but all of them should start in parallel roughly at the same time. I created .bat file, put my 3 commands in there and had run that bat file. But the commands are being executed in serial fashion(second command executes only after first one is finished). Is there a special way to do this in Windows?

What if i have to run the same command/exe i parallel, but with different arguments? I mean, lets suppose i have two commands, iperf.exe -s -u -i 1 10.10.100.1 and iperf.exe -s -u -i 1 10.10.100.2; Will these execute in parallel if i enter below lines in .bat file and run it?

start iperf.exe -s -u -i 1 10.10.100.1  
start iperf.exe -s -u -i 1 10.10.100.2  

And, even if they run in parallel, will there be any interruptions(even the slightest) while executing parallel processes like if one thread is dependent on another or will they execute strictly parallel like each command is an independent process? Because i need the programs to run at the same time and they should behave like separate and independent processes without any dependency or interruptions. Will START provide me with such kind of functionality?

4 Answers 4

4

In batch, use the start command, followed by the command you want to launch. All arg:

start iperf.exe -s -u -i 1 10.10.100.1
start iperf.exe -s -u -i 1 10.10.100.2

In PowerShell, use Start-Process (you can also call it "start", that's a built-in alias for Start-Process:

Start-Process iperf.exe -ArgumentList '-s -u -i 1 10.10.100.1'
Start-Process iperf.exe -ArgumentList '-s -u -i 1 10.10.100.2'

[Note: My answer appears to repeat information from the question because the question was edited to include information from my answer. The original question didn't mention the start command, it just asked how to start processes in parallel using batch or PowerShell.]

To answer the revised question: Both cmd's start and PowerShell's Start-Process spwan a child process, not a thread in the original process. In Windows, child processes are entirely independent from each other and from the parent. I've used both of these many, many times to launch applications that run separately, and can assure you that their operation is no more interdependent than if you had launched them in any other way.

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

2 Comments

even if the command has arguments. Suppose if i have to run a command like iperf -s -u -i 1 10.10.100.1 and iperf -s -u -i 1 10.10.100.2 in parallel. In this case, the command/exe is same but arguments are different. Will START work in this scenario?
Yes, batch is very simple that way. No need for quoting or anything like that. Just preface the command with start .
1

The equivalent of start in PowerShell is Start-Process as has been pointed out but getting the parameters to the exe is a bit tricky e.g.:

Start-Process iperf -arg -s,-u,-i,1,10.10.100.1
Start-Process iperf -arg -s,-u,-i,1,10.10.100.2

I assume the exe runs until you press Ctrl+C or press enter? Otherwise the window opens, runs and then exits.

2 Comments

Actually, you can quote all the arguments as a single string. -ArgumentList doesn't have to be an array of separate tokens. Start-Process iperf -ArgumentList '-s -u -i 1 10.10.100.1' will work just as well.
Yes that works and is easier. Sometimes I overthink these things. :-)
0

I think you just can't, neither in batch, nor in OS.

To minimize OS process loading overhead, you may try via Windows API to load all process suspended (CreateProcess, CREATE_SUSPENDED) and then, in a fast cycle start all threads (ResumeThread).

But I can't see any way to do that with command line, you have to go through programming.

1 Comment

I think you misunderstood the question. The focus wasn't on the timing of the launches and avoiding minute delays between when they begin. He said "roughly at the same time", not that they need to start as close to simultaneously as possible. The issue is that (a) he wants them to run in parallel rather than in sequence (i.e. that they start without waiting for the previous one to complete), and (b) he wants them to run independently of each other.
0

Sorry to post it as a Reply, but not enough reputation to comment. Insteady of:

Start-Process iperf -arg -s,-u,-i,1,10.10.100.1
Start-Process iperf -arg -s,-u,-i,1,10.10.100.2

You can do:

$params='-s -u -i 1 '
$ips=@('10.10.100.1','10.10.100.2')#and other more ips
$ips | foreach-Object{ Start-Process iperf -ArgumentList "$($params)$($_)"}

Then you can get the IP's from a list file, escalate and more. I was looking for something like this when I've find your question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.