-
-
Save gameame/837157 to your computer and use it in GitHub Desktop.
Execute a command on each line in input using the line as parameter
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 | |
# Example usage: | |
# ls|each cd PARAM\;pwd | |
import sys, subprocess | |
command = " ".join(sys.argv[1:]) | |
command = command.replace("PARAM", "%(p)s") | |
i = 0 | |
for parameter in sys.stdin.readlines(): | |
c = command % {'p': parameter.strip()} | |
print "***", c | |
p = subprocess.Popen(c, shell=True, executable="/bin/bash") | |
p.wait() | |
i += 1 | |
print "Executed %d times" % i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Equivalente a: