Skip to content

Instantly share code, notes, and snippets.

@mrenouf
Created October 28, 2010 13:49
Show Gist options
  • Save mrenouf/651383 to your computer and use it in GitHub Desktop.
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)
#!/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