python定时检查启动某个exe程序适合检测exe是否挂了
程序员文章站
2022-12-27 08:53:49
详见代码如下: 复制代码 代码如下: import threading import time import os import subprocess def get_pr...
详见代码如下:
import threading
import time
import os
import subprocess
def get_process_count(imagename):
p = os.popen('tasklist /fi "imagename eq %s"' % imagename)
return p.read().count(imagename)
def timer_start():
t = threading.timer(120,watch_func,("is running..."))
t.start()
def watch_func(msg):
print "i'm watch_func,",msg
if get_process_count('main.exe') == 0 :
print subprocess.popen([r'd:\shuaji\bin\main.exe'])
timer_start()
if __name__ == "__main__":
timer_start()
while true:
time.sleep(1)
复制代码 代码如下:
import threading
import time
import os
import subprocess
def get_process_count(imagename):
p = os.popen('tasklist /fi "imagename eq %s"' % imagename)
return p.read().count(imagename)
def timer_start():
t = threading.timer(120,watch_func,("is running..."))
t.start()
def watch_func(msg):
print "i'm watch_func,",msg
if get_process_count('main.exe') == 0 :
print subprocess.popen([r'd:\shuaji\bin\main.exe'])
timer_start()
if __name__ == "__main__":
timer_start()
while true:
time.sleep(1)
上一篇: 使用PHP计算两个路径的相对路径
下一篇: 汪直:从商人到海盗的明朝宦官