• We hope you have a fantastic holiday season to close out 2025! Thank you all so much for being part of the Tom's Guide community!

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!
 
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>
 


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