Skip to content

Instantly share code, notes, and snippets.

@ttback
Last active December 28, 2015 08:49
Show Gist options
  • Save ttback/7474582 to your computer and use it in GitHub Desktop.
Save ttback/7474582 to your computer and use it in GitHub Desktop.
Passing sys.stdin to sys.stdin of a subprocess
#!/usr/bin/python2.7
import subprocess
import os
import sys
from tempfile import NamedTemporaryFile
with NamedTemporaryFile('w', delete=False) as fout:
fout.write('import sys; print sys.stdin')
print subprocess.check_output(['python2.7', fout.name], stdin=sys.stdin)
os.unlink(fout.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment