Sign in with
Sign up | Sign in
Your question

Stop command in midway and restart it.

Last response: in Applications
Share
June 7, 2012 4:11:02 PM

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!
a b L Programming
June 7, 2012 4:25:59 PM

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.

  1. <commandToRun>
  2. ping 123.45.67.89 -n 1 -w 10000 > nul
  3. taskkill /F /IM <commandToRun>
  4. call <thisbatchfile>
June 7, 2012 5:19:54 PM

This won't work, because the <commandToRun> is a never ending command.
Related resources
a b L Programming
June 7, 2012 7:16:29 PM

What exactly is a "never ending command"? If you kill the process, it ends it.
a b L Programming
June 8, 2012 8:53:07 AM

Vitaminzed said:
This won't work, because the <commandToRun> is a never ending command.


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
!