Skip to content

Instantly share code, notes, and snippets.

@tadone
Created October 16, 2017 13:57
Show Gist options
  • Save tadone/0b3e0e90f9e5a7056e0d09808d966044 to your computer and use it in GitHub Desktop.
Save tadone/0b3e0e90f9e5a7056e0d09808d966044 to your computer and use it in GitHub Desktop.
[Replacing shell pipeline] #python
# Replacing shell pipeline
# output=`dmesg | grep hda`
# becomes:
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
#Alternatively:
# output=`dmesg | grep hda`
# becomes:
output=check_output("dmesg | grep hda", shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment