简体   繁体   中英

is it possible to do this with a batch file?

first post. I have an interesting request that has to do with batch files. I want to know if it's possible to code it so that the program that is launched with the bat file will terminate after a set amount of time, and then automatically restart, and then this just loops forever/until the program is exited.

anyone have any ideas?!

thanks!!

Something like this should work:

:TOP
  START /b notepad.exe
  PING 127.0.0.1 -n 5 -w 1000 > nul
  TASKKILL /im notepad.exe
GOTO :TOP

The /b for start will fire up a command in the background. We use notepad.exe in this example.

The strange ping command is a trick to get windows to sleep. -n takes a repeat count (5 in this case) and -w is the time in milisecs between pings. So this will ping 5 times with 1 sec delay between. in other words, it will wait for 5 secs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM