gpt4 book ai didi

windows - 并行启动多个任务并在 Windows 中等待它们?

转载 作者:可可西里 更新时间:2023-11-01 09:44:16 25 4
gpt4 key购买 nike

如何在批处理脚本中并行执行一些任务并等待它们?

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;

作为概念证明,我尝试了类似的方法,但它不起作用:

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"

我做错了什么?

最佳答案

我认为this is最简单的方法:

command1

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

command9

在下面的评论中有更多详细信息 this answer .

关于windows - 并行启动多个任务并在 Windows 中等待它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49050611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com