Skip to content

Instantly share code, notes, and snippets.

@jhaubrich
Created December 3, 2012 15:33
Show Gist options
  • Save jhaubrich/4195747 to your computer and use it in GitHub Desktop.
Save jhaubrich/4195747 to your computer and use it in GitHub Desktop.
subprocess sucks!
def subprocess_sucks():
""" This is what I want to do:
stdout = os.system("\
tail --lines 5000 %s/%s_%s/SP1*rpt\
| grep IDM-GIVE-X2 \
| grep -v Metric \
| tail --lines=39" % (path, month, day))
This is what it looks like:
"""
p1 = Popen(["tail", "--lines 5000", "%s/%s_%s/SP1*rpt" % (path, month, day)], stdout=PIPE)
p2 = Popen(["grep", "IDM-GIVE-X2"], stdout=PIPE)
p3 = Popen(["grep", "-v Metric"], stdout=PIPE)
p4 = Popen(["tail", "--lines=39"], stdout=PIPE)
p1.stdout.close()
p2.stdout.close()
p3.stdout.close()
p4.stdout.close()
output = p4.comminitcate()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment