欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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)