gpt4 book ai didi

batch-file - 等待并行批处理脚本

转载 作者:行者123 更新时间:2023-12-02 22:46:00 26 4
gpt4 key购买 nike

我有 4 个批处理文件。我想同时运行 one.battwo.bat。完成这两个批处理文件后,two.batfour.bat 应立即并行运行。我尝试了很多方法,但效果都很好。

谁能帮我解决这个问题吗?

最佳答案

使用我为Parallel execution of shell processes提供的解决方案的简化版本可以轻松完成此操作。 。请参阅该解决方案以了解文件锁定如何工作的说明。

@echo off
setlocal
set "lock=%temp%\wait%random%.lock"

:: Launch one and two asynchronously, with stream 9 redirected to a lock file.
:: The lock file will remain locked until the script ends.
start "" cmd /c 9>"%lock%1" one.bat
start "" cmd /c 9>"%lock%2" two.bat

:Wait for both scripts to finish (wait until lock files are no longer locked)
1>nul 2>nul ping /n 2 ::1
for %%N in (1 2) do (
( rem
) 9>"%lock%%%N" || goto :Wait
) 2>nul

::delete the lock files
del "%lock%*"

:: Launch three and four asynchronously
start "" cmd /c three.bat
start "" cmd /c four.bat

关于batch-file - 等待并行批处理脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12577442/

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