Created
December 18, 2008 20:06
-
-
Save kgaughan/37630 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# pipedarg | |
# by Keith Gaughan <http://talideon.com/> | |
# | |
# The software is hereby placed in the public domain, and the author | |
# disclaims ownership over it and all responsibility for any damage caused | |
# directly or indirectly through its use. It may be freely copied and/or | |
# mangled, provided that altered versions have a different name and are | |
# not attributed to the original author. | |
# | |
""" | |
Copies standard input to a temporary file and executes the command specified | |
in the arguments with the name of the temporary file as the last argument. | |
Obviously this won't work if the executed process forks a child to do its | |
work and exits immediately. | |
""" | |
from __future__ import with_statement | |
import sys | |
import os | |
import tempfile | |
with tempfile.NamedTemporaryFile() as tf: | |
tf.write(sys.stdin.read()) | |
tf.flush() | |
args = sys.argv[1:] | |
os.spawnvp(os.P_WAIT, args[0], args + [tf.name]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment