[英]How to make a bat file to abort itself if not finished in x seconds
How to make a bat file to abort itself if not finished in x seconds. 如果未在x秒内完成,如何制作bat文件中止自身。
In this script, some operation gets stuck sometimes, and I wish the whole script to exit(1) if it takes more than x seconds 在此脚本中,某些操作有时会卡住,我希望整个脚本在超过x秒后退出(1)。
Generate a Monitoring process at start of your Bat. 在蝙蝠开始时生成监视过程。 You have to set a Title for the process that will be killed after X seconds.
您必须为将在X秒后终止的进程设置标题 。
@echo on
::The Endtime in seconds
set "$Time=5"
::The title of the process to kill after [Endtime]
set "$Title=test"
title %$Title%
::Generating the monitoring process
(
echo timeout %$Time%
echo taskkill /F /FI "WINDOWTITLE eq %$Title%" /T) >timer.bat
::Running the monitoring Process in another thread
start timer.bat
::Here come your code
Pause
I just putted pause
to simulate your code replace it with your code. 我只是
pause
一下以模拟您的代码,用您的代码替换它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.