Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
755 views
in Technique[技术] by (71.8m points)

batch file - Start multiple tasks in parallel and wait for them in windows?

How do I execute some tasks in parallel in batch script and wait for them?

command1;

# command3, command4 and command5 should execute in sequence say task1
# command6, command7 and command8 should execute in sequence say task2
# both task1 and task2 should run independently

command3; command4; command5 | command6; command7; command8;

# should execute only after the above parallel tasks are completed

command9;

As a proof of concept I tried something like but it is not working:

echo "Starting"
start /wait wait20.bat   
start /wait wait40.bat 
echo "Finishing"

wait20.bat looks like:

echo "starting 20 seconds job"
timeout 20
echo "finishing 20 seconds job"

What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think this is the simplest way to do that:

command1

(
   start "task1" cmd /C "command3 & command4 & command5"
   start "task2" cmd /C "command6 & command7 & command8"
) | pause

command9

Further details in the comments below this answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...