5 ms·
from subprocess import Popen, PIPE p1 = Popen(["foo"], stdout=PIPE) p2 = Popen(["bar"], stdin=p1.stdout, stdout=PIPE) p1.stdout.close() # Allow p1
by Spiritus 10y ago
from subprocess import Popen, PIPE
p1 = Popen(["foo"], stdout=PIPE)
p2 = Popen(["bar"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output, _ = p2.communicate()
https://docs.python.org/3.5/library/subprocess.html#replacing-shell-pipeline https://docs.python.org/3.5/library/subprocess.html#replacin...
- mbrock 10y agoThanks. Maybe I'll make a public Gist that's a kind of "foo | bar" cookbook for different languages...
- lmm 10y agoWhat you actually do in Python is use https://github.com/kennethreitz/envoy https://github.com/kennethreitz/envoy
- mbrock 10y agoThat seems to recommend just calling the shell to do pipelines? Makes sense... Or maybe it parses that syntax itself?
- lmm 10y agoI believe it parses it itself.
- catchmrbharath 10y agoLooks like its not maintained.