【发布时间】:2018-08-15 11:23:33
【问题描述】:
我正在尝试将 powershell 的输出存储在 var 中:
import subprocess
subprocess.check_call("powershell \"Get-ChildItem -LiteralPath 'HKLM:SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall' -ErrorAction 'Stop' -ErrorVariable '+ErrorUninstallKeyPath'\"", shell=True, stderr=subprocess.STDOUT)
这样,使用check_call,就可以打印了,例如:
显示名称:Skype™
但是这种方式只能打印到屏幕上,所以我必须使用
import subprocess
output = subprocess.check_output("powershell \"Get-ChildItem -LiteralPath 'HKLM:SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall' -ErrorAction 'Stop' -ErrorVariable '+ErrorUninstallKeyPath'\"", shell=True, stderr=subprocess.STDOUT)
然后,使用 check_output,我得到:
显示名称:SkypeT
我该如何解决这个问题?
【问题讨论】:
标签: python encoding subprocess