Here is a simple script running subprocess that retrieves IP from the ifconfig
command output from the terminal.
I have noticed that subprocess.check_output()
always returns a value with
.
I desire to get a return value without
.
How can this be done?
$ python
>>> import subprocess
>>> subprocess.check_output("ifconfig en0 | awk '{ print $2}' | grep -E -o '([0-9]{1,3}[.]){3}[0-9]{1,3}'", shell=True)
'129.194.246.245
'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…