【发布时间】:2018-10-07 08:43:14
【问题描述】:
我编写了一个工具来获取 Windows 进程列表...然后搜索任何 Internet 浏览器(进程名称),例如 chrome.exe 、opera.exe .... 等,如果找到其中一个然后做一些事情。 ..如果不只是打印没有找到 我的代码:
import os
import time
def qa():
home = os.environ.get("HOMEDRIVE")
lol =home +"/"
mycurrent = os.getcwd()
change = os.chdir(lol)
mycurrent = os.getcwd()
d = os.popen("""wmic process get name | findstr /v "Name 'System Idle Process' System""").read().lower()
lists = ["opera.exe" , "chrome.exe" , "iexplore.exe" , "firefox.exe" , "microsoftedgecp.exe"]
for q in lists:
if any(item in q for item in d) :
qassam = os.popen("dir /s /b {}".format(lists[1])).read().strip()
print qassam
dir1 = os.path.dirname(qassam)
print dir1
#CreateShortCut_to_Desktop(qassam , dir1)
print time.time()
else:
print "nothing found"
break
qa()
我杀死了所有浏览器进程并运行了它应该给我的代码,但是……他保持循环并运行这段代码:
qassam = os.popen("dir /s /b {}".format(lists[1])).read().strip()
print qassam
dir1 = os.path.dirname(qassam)
print dir1
#CreateShortCut_to_Desktop(qassam , dir1)
print time.time()
这是我的输出:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe C:\Program 文件 (x86)\Google\Chrome\Application 1538829033.16 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe C:\Program Files (x86)\Google\Chrome\Application 1538829041.34 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe C:\Program Files (x86)\Google\Chrome\Application 1538829048.94 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe C:\Program Files (x86)\Google\Chrome\Application
【问题讨论】:
-
你能指定什么不起作用吗?请给出一个示例输出及其(错误)输出,以及所需的输出。
-
我修改它.....
标签: python list loops process wmic