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.
第一篇文章。我有一个有趣的请求,与批处理文件有关。我想知道是否可以对其进行编码,以便使用bat文件启动的程序将在一段时间后终止,然后自动重启,然后这将永远循环/直到程序退出。
anyone have any ideas?!
有人有主意吗?!
thanks!!
1 个解决方案
#1
2
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.
/ b for start将在后台启动命令。我们在这个例子中使用notepad.exe。
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.
奇怪的ping命令是一个让Windows睡眠的技巧。 -n需要重复计数(在这种情况下为5),-w是ping之间的毫秒数。所以这将平均5次,延迟1秒。换句话说,它将等待5秒。
#1
2
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.
/ b for start将在后台启动命令。我们在这个例子中使用notepad.exe。
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.
奇怪的ping命令是一个让Windows睡眠的技巧。 -n需要重复计数(在这种情况下为5),-w是ping之间的毫秒数。所以这将平均5次,延迟1秒。换句话说,它将等待5秒。