Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python子进程凌乱输出_Python_Subprocess - Fatal编程技术网

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说得好。从一开始就删除了这个骇客电话:)