Stop command in midway and restart it.

Vitaminzed

Honorable
Feb 22, 2012
2
0
10,510
Hi guys! Here's what I need done. I need a batch file to run a command; end it after 10 seconds; and restart the command in an endless loop. Thanks for any help!
 

Rusting In Peace

Distinguished
Jul 2, 2009
312
0
19,060
Try using something like the following.

Replace <commandToRun> with what you actually want to execute and <thisbatchfile> as the name. The ping command is just pinging an address that doesn't exist with a 10 second timeout.

Code:
<commandToRun>
ping 123.45.67.89 -n 1 -w 10000 > nul
taskkill /F /IM <commandToRun>
call <thisbatchfile>
 

Rusting In Peace

Distinguished
Jul 2, 2009
312
0
19,060


You might have viewed my reply before I edited it. Initially I had forgotten the taskkill statement so in that scenario then you would have just had n running instances of the command.

But with the taskkill statement and the /F flag then the process will be killed off