本文介绍了并行启动多个任务并在 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 看起来像:

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

我做错了什么?

推荐答案

我认为这是最简单的方法那个:

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.

这篇关于并行启动多个任务并在 Windows 中等待它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 17:27