Python子进程凌乱输出
使用以下代码:Python子进程凌乱输出,python,subprocess,Python,Subprocess,使用以下代码: output = subprocess.check_output(['wmic', 'PATH', 'Win32_videocontroller', 'GET', 'description']) print(output , "\n") 我得到下一个输出: b'Description \r\r\nNVIDIA GeForce 710M \r\r\nIntel(R) HD Graphics 4000 \r\r\n\r\r\n'
output = subprocess.check_output(['wmic', 'PATH', 'Win32_videocontroller', 'GET', 'description'])
print(output , "\n")
我得到下一个输出:
b'Description \r\r\nNVIDIA GeForce 710M \r\r\nIntel(R) HD Graphics 4000 \r\r\n\r\r\n'
当我在CMD中使用commando
wmic路径win32\u videocontroller get description
时,我只得到了视频卡信息。在python中也可以这样做吗?没有/r/r/r/r的东西吗?使用翻译
print output.translate(None, '\r\n')
调用函数时使用参数“universal_newlines=True”:
output = subprocess.check_output(['wmic', 'PATH', 'Win32_videocontroller', 'GET', 'description'], universal_newlines=True)
print(output , "\n")
TypeError:expected bytes、bytearray或buffer兼容对象|是否收到错误消息:(为什么调用str(bytes_对象)
在这里,你为什么要向新手推荐它?第二个代码示例应该是你答案中唯一的一个。@joey:我希望你使用了启用文本模式的universal\u newlines=True
解决方案(为什么text\u mode
拼写为universal\u newlines
不清楚).@J.F.Sebastian说得好。从一开始就删除了这个骇客电话:)