Created
October 28, 2010 13:49
-
-
Save mrenouf/651383 to your computer and use it in GitHub Desktop.
Like xargs, but for STDIN (run a command for each line, piping the line to STDIN)
This file contains hidden or 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/python | |
import sys, subprocess | |
def main(args=sys.argv): | |
if len(args) < 2: | |
print "Usage: %s <command>" % (args[0]) | |
exit 1 | |
while True: | |
try: line = raw_input(None) | |
except EOFError: break | |
if line != "": | |
proc = subprocess.Popen(args[1:], stdin=subprocess.PIPE) | |
proc.stdin.write(line) | |
proc.stdin.close() | |
proc.wait() | |
if __name__=="__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment