【发布时间】:2016-05-20 08:54:20
【问题描述】:
我目前正在使用批处理文件在我的计算机上运行模拟,以使事情更加自动化,而不必在前一个模拟完成后自己启动每个模拟。
但是我注意到,当我运行批处理文件时,如果其中一个模拟无法完成并且只运行了几个小时,我无法跳过终止它并跳到下一个模拟。这意味着,如果它在我的 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 脚本自动生成它们,所以我不介意看起来像这样的重复解决方案,因为只需将其添加到字符串 I用于创建批处理文件:
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 命令只是暂停执行而不是终止它。
我尝试了以下使用,How to set a timeout for a process under 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 秒但继续下一次运行
感谢您的帮助。
【问题讨论】:
-
我昨天看了这个并尝试了一些不同的东西(见问题底部的编辑)但无法让它工作。
-
1) 你忘了描述“没有成功”是什么意思。发生了什么? 2)我猜没有成功的是文件重定向。你需要
start cmd /c "ogs blabla > blabla"才能工作。 3) 实际上我推荐了其他答案,请参阅我的链接,因此如果模拟在此之前实际完成,则不要总是等到超时。 4) 你的taskkill中需要ogs.exe而不是ogs。 -
让它工作!谢谢!
标签: windows batch-file timeout