【发布时间】:2018-07-30 10:50:59
【问题描述】:
我想自动检查机器上是否安装了一些 KB。 我的python脚本的一部分:
import subprocess
result = subprocess.run(['cmd', '/c wmic qfe'], shell=True, stdout=subprocess.PIPE)
ftemp = open('mylog.txt','w') #just to check what is going wrong
ftemp.write(str(result.stdout))
ftemp.close()
if str(result.stdout).find('KB2999226')==-1:
print('Nah, you don't have KB')
sys.exit()
执行时我在 shell 中得到了什么:
qfe" - Alias not found.
Nah, you don't have KB
mylog.txt:
b''
因此,破折号或编码看起来像是一些愚蠢的问题。我尝试了各种命令,但都没有成功。 (是的,“dism”会导致另一吨错误)。 有什么建议吗?
【问题讨论】:
-
'Nah, you don't have KB'中的单引号是错字吗? -
但是命令从cmd成功执行?所以只是python脚本导致了错误?
-
另外,
wmic path win32_quickfixengineering get KB2999226工作了吗? -
1) 消息是俄语,没有像“不要”这样的规范字符。 2)来自 cmd 的命令会出现相同的错误。 3) `result = subprocess.run(["cmd", '/c dism /Online /Get-Packages'], shell=True, stdout=subprocess.PIPE)
- returns some unreadable text in the result.stdout, whiledism /Online /Get-Packages` 完美运行来自 cmd。 -
我不喜欢在您收到的错误消息中单次出现双引号。确定是
qfe" - Alias not found.而不是"qfe" - Alias not found.???在后一种情况下,如果你从命令行输入cmd /c wmic qfe会发生什么?