并行启动多个任务,然后在Windows中等待它们? [英] Start multiple tasks in parallel and wait for them in windows?

查看:102
本文介绍了并行启动多个任务,然后在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"

我在做什么错了?

推荐答案

我认为这是最简单的方法

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中等待它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆