python定時檢查啟動某個exe程序適合檢測exe是否掛了
更新時間:2013年01月21日 10:44:29 作者:
定時檢查啟動某個exe程序這種情況下適合檢測某個exe程序是否掛了,感興趣的朋友可以了解下,希望本文對你有所幫助
詳見代碼如下:
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)
相關文章
僅用500行Python代碼實現(xiàn)一個英文解析器的教程
這篇文章主要介紹了僅用500行Python代碼實現(xiàn)一個英文解析器的教程,自然語言處理近來也是業(yè)界中一個熱門課題,作者為NLP方向的開發(fā)者,需要的朋友可以參考下2015-04-04

50行Python代碼實現(xiàn)視頻中物體顏色識別和跟蹤(必須以紅色為例)
本文通過50行Python代碼實現(xiàn)視頻中物體顏色識別和跟蹤效果,通過實例截圖和實例代碼給大家講解的非常詳細,需要的朋友可以參考下
2019-11-11 
python計算階乘和的方法(1!+2!+3!+...+n!)
今天小編就為大家分享一篇python計算階乘和的方法(1!+2!+3!+...+n!),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
2019-02-02