【问题标题】:Inserting 'waitfor' command in called and calling batch files在调用和调用批处理文件中插入“等待”命令
【发布时间】:2013-11-16 09:48:17
【问题描述】:

我有 3 个调用批处理文件,例如 called1.bat :

调用1.bat

taskkill /f /im firefox.exe
net stop W3SVC
sc config W3SVC start= demand
net start W3SVC

和一个调用 Master.bat 文件,它调用所有三个调用的批处理文件,如下所示:

Master.bat

@echo off 
setlocal enabledelayedexpansion
REM 1st for loop:
for /F "delims= " %i in (C:\test\Serverlist1.txt) do ( psexec \\%i start C:\data\called1.bat )
REM 2nd for loop:
for /F "delims= " %i in (C:\test\Serverlist2.txt) do ( psexec \\%i start C:\data\called2.bat )
REM 3rd for loop:
for /F "delims= " %i in (C:\test\Serverlist3.txt) do ( psexec \\%i start C:\data\called3.bat )

其实我想将 Master.bat 文件中的不同信号发送到三个被调用的 .bat 文件中,以便在一些远程服务器上运行它们,如下所示:

called1.bat file to wait until the "SIGNAL1" is received from Master.bat
called2.bat file to wait until the "SIGNAL2" is received from Master.bat
called3.bat file to wait until the "SIGNAL3" is received from Master.bat

我应该将waitfor SIGNAL1 命令放在 called1.bat 文件的什么位置?

我应该将waitfor /SI SIGNAL1 命令放在Master.bat 文件中的什么位置,以将信号发送到 called1.bat 以开始运行?其他文件也是如此..

我的主要目的是:在 Master.bat 文件中,2nd for loop 应该只在 1st for loop 完成其完整执行后才开始运行,同样3rd for loop2nd for loop 之后才开始运行@这就是为什么更喜欢 @ 987654332@方法到目前为止。

【问题讨论】:

  • @Endoro...请问你能帮我吗?
  • @foxidrive..我也想请你帮忙。
  • 批量使用for循环变量,百分比为%%i。什么是信号,批次如何接收?
  • 我尝试使用this link..
  • 我的 @Endoro..This question 将帮助您了解我的确切要求。

标签: batch-file wait remote-access psexec


【解决方案1】:

基本思路可以是:

在master.bat中

for each server in list (
    create the remote process
    spawn a local copy of waitfor to know when remote ends
)
send signal to remote systems to start work
loop waiting for local waitfors to end on signals from remote servers

waitfor 的本地副本应生成为 `start "" /b waitfor remoteserversignal",每个服务器的远程服务器信号都是唯一的,因此我们知道它何时完成

tasklist / pslist / wmic 可用于了解本地等待副本何时完成。

在 remote.bat 中

wait for master signal to start
do work
send signal to master to signal end of work

【讨论】:

  • 感谢 MC.. 的概念!成功实施..:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-30
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多