« Back to Index

Python 2: execute multiple shell cmds and print result

View original Gist on GitHub

Python 2: execute multiple shell cmds and print result.py

from subprocess import Popen, PIPE

cmd = 'grep "^name" /etc/resolv.conf | grep -v "0.0.0.0" | cut -d " " -f 2'
result = Popen(cmd, shell=True, stdout=PIPE)
print result.stdout.read()