leon
leon

Reputation: 10395

Setup timeout for commands in Windows .bat file

I wrote a windows .bat script. To run a list of commands and then shut down the computer.

such as:

c:\someapplication.exe
c:\someapplication2.exe
Shutdown -s -t 0

Sometimes, "c:\someapplication.exe" freezes and do not respond. How can I setup timeout for my command "c:\someapplication.exe", so that after a certain amount of time, I want windows to force close the application and continue the rest of the commands?

Upvotes: 4

Views: 10383

Answers (3)

Bali C
Bali C

Reputation: 31231

You could use a combination of ping and taskkill to do this.

start c:\someapplication.exe
ping 127.0.0.1 -n seconds
taskkill /im someapplication.exe /f 
start c:\someapplication2.exe
ping 127.0.0.1 -n seconds
taskkill /im someapplication2.exe /f 
Shutdown -s -t 0 /f

Just replace seconds in the ping command with the number of seconds you want to wait before attempting to close the process (enough time so if it's still running it must have crashed). Then the rest of the app can continue until it is forced to shutdown.

Upvotes: 3

Shahin
Shahin

Reputation: 302

You can run your exe program and the shutdown command at once and put the timeout in shutdown options [-t]. To run multiple command at once, use "start" command ("start [yourProgram.exe]"). To do force shutdown use [-f] option.

good luck

Upvotes: 2

PA.
PA.

Reputation: 29339

if you may afford that all someapplications run in parallel try this

 start someapplication
 start someapplication2
 wait n secons
 shutdown

choose your value of n so that it does not proceed with shutdown while someapplications still run legit

or alternatively

 start someapplication
 wait n seconds
 start someapplication2
 wait m seconds
 shutdown

for wait there are many solutions around, google some bat wait timeout

Upvotes: 3

Related Questions