繁体   English   中英

批处理文件超时以终止当前命令并执行下一个命令

[英]Batch file timeout to terminate current command and execute next one

我目前正在使用批处理文件在计算机上运行仿真,以使事情自动化一些,而不必在上一个仿真完成后自己启动每个仿真。

但是,我注意到,当我运行批处理文件时,如果其中一个模拟无法完成,并且只能连续运行几个小时,则无法跳过终止它并跳至下一个模拟。 这意味着,如果它在我的200次仿真中跳闸了……那么我就失去了一个周末的仿真时间。

我想知道你们中的一个人是否可以告诉我如何在执行中包括一个“计时器”条件,以便在运行5小时后终止并继续执行下一个命令。

有关信息,我的文件如下所示(ogs是我的可执行文件,路径是可执行文件查找输入的位置,然后将控制台输出到名为Screen_out.txt的文件):

ogs Depth_200_Poro_15_Thick_40_Perm_100\ax    >    Depth_200_Poro_15_Thick_40_Perm_100\Screen_out.txt
ogs Depth_200_Poro_15_Thick_174_Perm_100\ax    >    Depth_200_Poro_15_Thick_174_Perm_100\Screen_out.txt
ogs Depth_200_Poro_15_Thick_350_Perm_100\ax    >    Depth_200_Poro_15_Thick_350_Perm_100\Screen_out.txt

我大约有200行,但是我使用Python脚本自动生成了它们,所以我不介意像这样的重复解决方案,因为将它添加到我用来创建的字符串中就可以了。批处理文件:

set timer to 5hrs, if timer is reached terminate and move on
ogs Depth_200_Poro_15_Thick_40_Perm_100\ax    >    Depth_200_Poro_15_Thick_40_Perm_100\Screen_out.txt
set timer to 5hrs, if timer is reached terminate and move on
ogs Depth_200_Poro_15_Thick_174_Perm_100\ax    >    Depth_200_Poro_15_Thick_174_Perm_100\Screen_out.txt
set timer to 5hrs, if timer is reached terminate and move on
ogs Depth_200_Poro_15_Thick_350_Perm_100\ax    >    Depth_200_Poro_15_Thick_350_Perm_100\Screen_out.txt

我环顾四周,但似乎在Windows下,timeout命令仅暂停执行,而不是终止执行。

我已经尝试过使用以下方法, 如何在Windows 7下为进程设置超时?

start   "ogs    Depth_4000_Poro_23_Thick_350_Perm_650\ax    >    Depth_4000_Poro_23_Thick_350_Perm_650\Screen_out.txt"
timeout /t 10
taskkill /im ogs.exe /f 
timeout /t 7

上面的方法似乎可以正常工作,程序在10秒钟后执行并关闭,但是命令窗口随即打开

start   "ogs    Depth_4000_Poro_23_Thick_350_Perm_650\ax    >    Depth_4000_Poro_23_Thick_350_Perm_650\Screen_out.txt"

杀死ogs.exe时不会关闭。

---- 2016年7月29日更新-----

因此,目前我正在使用以下内容:

start cmd /c    "ogs    Depth_4000_Poro_23_Thick_350_Perm_650\ax    >    Depth_4000_Poro_23_Thick_350_Perm_650\Screen_out.txt" //executes the command as before
timeout /t 34000// waits for 34000 seconds
taskkill /im ogs.exe /f // terminates the program after the 10 seconds
timeout /t 7 // waits 10 seconds to insure the program has terminated correctly

我的问题是,当我的程序ogs.exe在34000秒之前完成时,计算机将等待超时,然后启动下一个ogs.exe运行。 如果程序在34000秒超时之前完成,我希望它等待最多34000秒,但继续进行下一次运行

谢谢您的帮助。

感谢@CherryDT设法使它能够使用:

start cmd /c    "ogs    Depth_4000_Poro_23_Thick_350_Perm_650\ax    >    Depth_4000_Poro_23_Thick_350_Perm_650\Screen_out.txt" //executes the command as before
timeout /t 10 // waits for 10 seconds
taskkill /im ogs.exe /f // terminates the program after the 10 seconds
timeout /t 7 // waits 10 seconds to insure the program has terminated correctly

其他有用的线程在这里: 批处理文件-每20分钟重新启动一次程序

如何在Windows 7下为进程设置超时?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM