如何按顺序运行一组并行批处理文件

时间:2014-04-16 17:46:24

标签: windows batch-file parallel-processing cmd

我正在尝试编写一个测试bat文件,该文件将执行以下操作:

  • 从服务器下载文件
  • 将文件上传到同一台服务器

我需要三台笔记本电脑才能同时执行下载和上传。因此,我创建了一个名为3-chanD.bat的脚本:

*echo /////////3-channel-Downloading////////
start  cmd.exe /k >time2 timeit chan6D.bat
start  cmd.exe /k >time3 timeit chan11D.bat
start  cmd.exe /k >time1 timeit chan1D.bat*

chan6D.bat基本上是从服务器到我的一台笔记本电脑的脚本应对文件:

*xcopy  "C:\Documents and Settings\All Users\Documents\test" "\\192.168.0.102\SharedDocs\test"  /Y /E /S*

与chan1D.bat和chan11D.bat相同:

*echo /////////channel 6 Downloading////////
xcopy  "C:\Documents and Settings\All Users\Documents\test" "\\192.168.0.102\SharedDocs\test"  /Y /E /S*
*echo /////////channel  11 Downloading////////
xcopy  "C:\Documents and Settings\All Users\Documents\test" "\\192.168.0.104\SharedDocs\test"  /Y /E /S*

上传脚本执行相反的工作。

问题是我需要坐在笔记本电脑旁等待这三台笔记本电脑完全下载,然后手动运行上传脚本。我尝试写一个脚本:

*@echo off
echo /////////3-channel-Downloading////////
call  3-chanD.bat
echo /////////3-channel-Uploading////////
call  3-chanU.bat
pause*

但它只是在一秒内运行3-chanD.bat和3-chanU.bat。它不会等到下载完成。 有没有办法并行执行一组命令,然后并行执行另一组命令?

1 个答案:

答案 0 :(得分:0)

让每个批处理文件创建一个标记文件,执行xcopy,并在xcopy完成后删除标记文件。

type nul > "%temp%\xcopy1.tmp"
xcopy  "C:\Documents and Settings\All Users\Documents\test" "\\192.168.0.102\SharedDocs\test"  /Y /E /S
del "%temp%\xcopy1.tmp"

您的启动批处理文件可以检查循环中是否存在所有三个标记文件,并在它们不再存在时启动上载过程。