我尝试获取所有进程,但我不知道如何只获取这类进程。
y1aodyip1#
#!/usr/bin/python # -*- coding: utf8 -*- import subprocess import psutil pids = [] cmd = 'powershell "gps | where {$_.MainWindowTitle } | select Id' proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) for line in proc.stdout: if line.rstrip(): #print(line.decode().rstrip()) pids.append(line.decode().rstrip()) pids.remove(' Id') pids.remove(' --') for pid in pids: process = psutil.Process(int(pid)) process_name = process.name() print(process_name)
字符串这就是我的回答
1条答案
按热度按时间y1aodyip1#
字符串
这就是我的回答