Skip to content

Instantly share code, notes, and snippets.

@benjamingeiger
Created April 27, 2014 07:53
Show Gist options
  • Save benjamingeiger/11340007 to your computer and use it in GitHub Desktop.
Save benjamingeiger/11340007 to your computer and use it in GitHub Desktop.
Python subprocess emulating a filter.
infile = open(inputfilename, "r")
outfile = open(outputfilename, "w")
filter1 = subprocess.Popen(commandline1, stdin=infile, stdout=subprocess.PIPE, stderr=None)
filter2 = subprocess.Popen(commandline2, stdin=filter1.stdout, stdout=outfile, stderr=None)
filter1.stdout.close() # required so filter2 can get SIGPIPE, apparently
filter1.wait()
filter2.wait()
infile.close()
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment