【发布时间】:2022-11-14 14:37:57
【问题描述】:
我试图找到在我的系统上运行的特殊进程。为此,拉出目前在我的系统上运行的所有进程并将其存储在一个名为“名称”的变量中。现在我想解析存储在这个“名称”变量中的数据,并找到我需要的特定过程。
import subprocess
output = subprocess.check_output(('TASKLIST', '/FO', 'CSV')).decode()
# get rid of extra " and split into lines
output = output.replace('"', '').split('\r\n')
keys = output[0].split(',')
proc_list = [i.split(',') for i in output[1:] if i]
# make dict with proc names as keys and dicts with the extra nfo as values
proc_dict = dict((i[0], dict(zip(keys[1:], i[1:]))) for i in proc_list)
for name, values in sorted(proc_dict.items(), key=lambda x: x[0].lower()):
print(name)
这是我的代码。
【问题讨论】: