简体   繁体   English

Python子进程凌乱的输出

[英]Python subprocess Messy output

With the following code: 使用以下代码:

output = subprocess.check_output(['wmic', 'PATH', 'Win32_videocontroller', 'GET', 'description'])
    print(output , "\n")

I get the next output: 我得到下一个输出:

b'Description                \r\r\nNVIDIA GeForce 710M        \r\r\nIntel(R) HD Graphics 4000  \r\r\n\r\r\n'

When I use the commando wmic path win32_videocontroller get desription in my CMD I get only the videocard info back. 当我在我的CMD中使用commando wmic path win32_videocontroller get desription ,我只返回了视频信息。 Is this possible in python aswell? 这在python中也可能吗? With out the /r/r/r/r things? 没有/ r / r / r / r的东西?

Use the argument "universal_newlines=True" when you call the function: 调用函数时使用参数“universal_newlines = True”:

output = subprocess.check_output(['wmic', 'PATH', 'Win32_videocontroller',  'GET', 'description'], universal_newlines=True)
print(output , "\n")

使用translate

print output.translate(None, '\r\n')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM