有效的方式来继续检查,如果一个程序仍在使用批处理脚本运行 [英] efficient way to keep checking if a program is still running with a batch script
本文介绍了有效的方式来继续检查,如果一个程序仍在使用批处理脚本运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个批处理脚本,我想检查是否program1.exe仍在运行的脚本的一部分。一旦program1.exe不再运行,我想要做的事。
I would like to write a batch script, and part of the script I want to check if program1.exe is still running. Once program1.exe is no longer running, I want to do something.
我可以写一个while循环要做到这一点,但它会继续检查一遍又一遍,我的CPU中使用了我的一个核心的100%。
I can write a while loop to do this, but it will keep checking over and over and use up 100% of one of my cores in my CPU.
有没有检查的有效途径?也许这会检查这个条件每秒一次黑客攻击?
Is there an efficient way to check? Maybe a hack that checks this condition once a second?
感谢
推荐答案
尝试这样的:
@echo off
Set "MyProcess=Notepad.exe"
:start
tasklist | find /i "%MyProcess%">nul && goto:wait || start %MyProcess%
goto:start
:wait
ping localhost -n 3 >nul
goto:start
只是你的程序的名称替换Notepad.exe的
Just replace Notepad.exe with the name of your program
这篇关于有效的方式来继续检查,如果一个程序仍在使用批处理脚本运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文