python - os.popen subprocess conversion -


This snippet gives me the dotted quad of my BSD network interface. How would I use the subprocess module instead?

  ifcfg_lines = os.popen ("/ sbin / ifconfig fxp0"). Readlines () x = string.split (ifcfg_lines [3]) [1]  

It seems that I can not use subprocessation in the same way. I do not think I want shell = true or pipe. What should I do to index output?

Thank you. Poppin, PIPE ifcfg_lines = Popen ("/ sbin / ifconfig fxp0", from

  subprocess imports   

For a little more beauty, hide details:

  DEF getBSDIP (): poppin import from the subprocess import, pipe import string = current ("/ sbin / ifconfig  

if you are going to use subprocess Elegance to this is a little limited because you essentially have screencrap If you really want a general solution, then use the socket library, i.e. handle Python portability.

Often, when you are doing something like this, you are scripting scripts here. You see a little code and you want to have a better cleaner way to do this, that means you have to question your beliefs, and change the solution's algorithm or architecture


Comments

Popular posts from this blog

MySql variables and php -

php - Laravel - Overriding a resource route into a different route filter group -

url rewriting - How to implement the returnurl like SO in PHP? -