Hi I am trying to run this command in python's subprocess with shlex split, however, I haven't found anything helpful for this particular case :
ifconfig | grep "inet " | grep -v 127.0.0.1 | grep -v 192.* | awk '{print $2}'
I get an with ifconfig error because the split with the single and double quotes and even the white space before the $ sign are not correct. Please Help.
You can use
shell=True
(shell will interpret|
) and triple quote string literal (otherwise you need to escape"
,'
inside the string literal):or you can do it in harder way (Replacing shell pipeline from
subprocess
module documentation):