python - 在多个同步批处理文件完成后执行 1 个批处理文件

标签 python windows batch-file cmd nested

我已经阅读了以下两个帖子,发现它们似乎都没有回答我的问题 How to call one batch file after another , Execute batch file after another batch file completes .

我正在尝试通过批处理文件在 Windows Server 2012 R2 Standard 上运行一系列 6 个 python 脚本。我希望前 5 个脚本同时运行 (Processing.bat),它目前由五个子 bat 文件组成(North.bat、West.bat、South.bat、Central.bat、Northeast.bat)。完成后,它应该运行一个最终脚本,该脚本与前 5 个(Merge.bat)的输出一起使用。

我已经尝试了几种 call 和 start/wait 的组合,但似乎没有什么是正确的。目前我的主要 bat 文件如下所示:

start /wait Processing.bat
start /wait Merge.bat

Processing.bat 看起来像:

start North.bat
start South.bat
start NorthEast.bat
start West.bat
start Central.bat

IF %ERRORLEVEL% EQU 0 EXIT 

每个子 bat 看起来像:

start /wait C:\Python27\ArcGIS10.4\python.exe E:\TestScript.py Central 

IF %ERRORLEVEL% EQU 0 EXIT

最后 merge.bat 看起来像:

start /wait C:\Python27\ArcGIS10.4\python.exe E:\MergeSDE.py

IF %ERRORLEVEL% EQU 0 EXIT

使用此设置,所有 6 个脚本将同时运行(而不是 5 个后跟 1 个)。但是相应的命令提示符窗口将保持打开状态,直到每个脚本完成(7 个窗口)。更重要的是,如果我要将 Processing.bat 中的“开始”更改为“开始/等待”,它将一个接一个地运行(前 5 个中的哪一个,我不想要),但是使用“开始/等待” "在主批处理中,所有子批处理同时运行。

最佳答案

这是解决这个问题最简单的办法:

(
start North.bat
start South.bat
start NorthEast.bat
start West.bat
start Central.bat
) | set /P "="

call Merge.bat

更多详情请访问 How to wait all batch files to finish before exiting? .

关于python - 在多个同步批处理文件完成后执行 1 个批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42771581/

相关文章:

batch-file - 将 STDOUT 放入变量中

windows - 如何为 FOR 循环中的每个命令获取 ERRORLEVEL?

python - 用python更改音频输出设备

python - 如何通过Scrapy收集jpeg

用于安装多个 perl 模块的 Windows 批处理文件 - 仅运行第一行

c++ - Windows 驱动程序向 WinDbg 控制台列出文件

c++ - 在目录中获取目录中的文件列表

python - 通过套接字接收的总字节数与实际文件大小不同

python - Azure 笔记本上的计划

C# - ScheduledTasks 类 - 如何指定 localhost?