Anybody know if there is cmd script that does that and/or a command line tool ready for the job?
Create the three batch files below. Main.bat launches 1.bat and 2.bat
1.bat and 2.bat write out temporary files for which main.bat checks. While 1.bat and 2.bat are working, main.bat reports back that processing is still occurring. When you hit enter on either 1.bat or 2.bat's open window, the temporary file is deleted, and the program exits. This simulates processing stopping for that .bat file. If you do this for both 1 and 2.bat, main.bat reports to you that processing has completed for these processes. You can make 1.bat and 2.bat do anything you want, so long as you clear the temporary file when you are finished. At this point main.bat can do anything you want it to do as well.
echo %time% > 1.tmp pause del 1.tmp exit
echo %time% > 2.tmp pause del 2.tmp exit
@echo off start "1" 1.bat start "2" 2.bat @ping -n 1 127.0.0.1 > nul :loop @echo Processing...... if not exist *.tmp goto :next @ping -n 5 127.0.0.1 > nul goto loop :next @echo Done Processing!
Simple enough, provided the processes don't need standard input or output. From the command line, or in a batch file:
process1 | process2 | process3 | process4
This will run all four processes simultaneously, and won't return until they've all exited. (Possible exception: if a process explicitly closes the standard output it might be treated as if it had exited. But that's unusual, very few processes do that.)
I'm not sure exactly how many processes you can launch simultaneously this way. I've tried up to ten.
The only way to do this is to start separate batch files (see
start /?) that run the individual task and write a text file upon completion. Then, you periodically check whether the text files have been made.
You might look at the Powershell Start-Job cmdlet. It should allow you to do this. More here Powershell is Microsoft's shell of choice. It is much more powerfull than cmd scripts and well worht the investment of your time
Or you can use this: http://www.out-web.net/?p=167
I did it, it works, however it happens sometimes that the PID of the finished process is immediately re-used by another Windows processus which just started, and it makes the detection of the end of your processus hazardous/erroneous.
I was also looking for similar task. Objective was to run multiple commands parallel and extract output (stdout & error) of all parallel processes. Then wait for all parallel processes to finish and execute another command. Following is a sample code for BAT file, can be executed in CMD:
start "" /B cmd /c ping localhost -n 6 ^>nul
timeout /t 5 /nobreak
start "" /B /D "C:\users\username\Desktop" cmd /c dir ^> dr.txt ^2^>^&^1
start "" /B cmd /c ping localhost -n 11 ^>nul
timeout /t 10 /nobreak
) | pause
timeout /t 12 /nobreak
All the statements inside
() are executed first, wait for them to complete, then last two lines are executed. All commands begining with
start are executed simultaneously.