joey
joey

Reputation: 241

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 desriptionin my CMD I get only the videocard info back. Is this possible in python aswell? With out the /r/r/r/r things?

Upvotes: 1

Views: 426

Answers (2)

Matthew Runchey
Matthew Runchey

Reputation: 224

Use the argument "universal_newlines=True" when you call the function:

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

Upvotes: 2

David
David

Reputation: 6571

Use translate

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

Upvotes: 1

Related Questions