【发布时间】:2021-04-13 14:55:53
【问题描述】:
所以我有一个带有代码的脚本
import os
import subprocess
import psutil
def checkIfProcessRunning(processName):
'''
Check if there is any running process that contains the given name processName.
'''
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False;
然后在执行之后
while True:
if checkIfProcessRunning('TDR'):
print('TDR (tdr.exe) is running')
else:
print('TDR (tdr.exe) is not running')
subprocess.call("cmd /c data.vbs") # Executes other code
整个脚本检测进程 tdr.exe 是否打开,当代码检测到它未打开时,我希望它打开一些其他代码,但我希望它只做它一次而不是循环。
【问题讨论】:
-
请修正你的代码缩进