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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -