如何在批处理文件中添加停止执行命令 [英] How to add a stop execution command in a batch file
本文介绍了如何在批处理文件中添加停止执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须创建一个执行一些操作的批处理文件,但是我需要添加一些命令,以便在超过30分钟的执行时间后它将停止执行.
I have to create a batch file which will perform some operation but I need to add some commands so that it will stop execution if it exceeds 30 minutes of execution time.
有人可以帮忙吗? 我是批处理脚本的新手.
Can anybody help? I am new to batch scripting.
推荐答案
相反,您需要从另一个调用.bat并在30分钟后检查它是否仍在运行
Rather you need to call your .bat from another one and check after 30 minutes if it's still running
@echo off
set "my_bat=E:\MyBat.bat"
for /f "delims=" %%a in ('wmic process call create "%my_bat%" ^|find "ProcessId"') do (
for /f "tokens=2 delims=;= " %%# in ("%%a") do set "PID=%%#"
)
::echo %PID%
::sleep for 30 minutes
ping 1.1.1.1 -n 1 -w 1800000 > nul
::kill the bat
tskill %PID% >nul 2>&1
您需要将 my_bat 的位置更改为您的完整路径.
you need to change the location of my_bat to the yours with full path.
这篇关于如何在批处理文件中添加停止执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文