windows - How to get the output of subprocess.check_output() python module? -


i'm trying information command prompt (cmd - windows ) in python, using module subprocess :

ipconfig = subprocess.check_output("ipconfig") print(ipconfig) 

the result is:

b'\r\nwindows ip configuration\r\n\r\n\r\nethernet adapter local area connect:\r\n\r\n   connection-specific dns suffix  . : xx.xxx\r\n   ipv4 address. . . . . . . . . . . : xxxxxxxxx\r\n   subnet mask . . . . . . . . . . . : xxxxxxxxxx\r\n   default gateway . . . . . . . . . : xxxxxx\r\n' 

i've read documentation on module subprocess didn't find fits problem.

i need information in nice formatted string ... not that, do?

(i think problem here string format, if have tips getting nice output without needing of string formatting, appreciate)

i know can ip address socket module, i'm giving example.

you printing bytes string value, , print() turned unicode string using repr(). want decode value unicode instead:

import sys  print(ipconfig.decode(sys.stdout.encoding)) 

this uses encoding of console interpret command output.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -