Reputation:
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.
Upvotes: 2
Views: 202
Reputation: 57322
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
you need to change the location of my_bat to the yours with full path.
Upvotes: 1