下面的列表建议只有满足domain
和userl
条件的用户才应该添加到users()
。但是我在sorted_list
中得到了空结果。有人能告诉我为什么吗?你知道吗
domain = 'domainanme'
user_list = [test1, test2, test3]
new_list = []
for userl in user_list:
try:
out = subprocess.check_output(["tasklist", "/V", "/FO", "List", "/FI", "USERNAME eq {0}\{1}" .format(domain, userl)], stderr=subprocess.STDOUT)
users = [item for item in out.split() if domain in item and userl in item]
sorted_list = set(users)
print sorted_list
if sorted_list != None: # this was an attempted to remove the EMPTY items
for name in sorted_list:
print name
new_list.append(name)
else:
pass
打印姓名输出
set([])
set([])
set([])
输出如下:
输出中的域名是大写的;请确保考虑到这一点。规范化both的大小写以确保不区分大小写的匹配:
我会更智能地解析输出,因为上面的内容很容易导致误报(进程名中包含域和用户名,即使是重叠的文本,也会匹配)。你知道吗
相关问题 更多 >
编程相关推荐