Aqui está um peixe ...
import popen2, sys
def loopy_subprocess(arga, argb, iterations, command = 'echo'):
for i in range(int(iterations)):
p = popen2.Popen4((command, arga, argb))
p.wait()
print(p.fromchild.readlines())
if __name__ == '__main__':
try:
arga = sys.argv[1]
argb = sys.argv[2]
iterations = sys.argv[3]
except:
print("You didn't supply enough arguments\n"+\
"Usage: python script.py arga argb iterations\n"+\
"Warning - unsafe. No input validation and doesn't account for spaces in arguments\n"+\
"Optionally supply the command to be run as a final argument\n")
quit()
try:
command = sys.argv[4]
loopy_subprocess(arga, argb, iterations, command)
except:
loopy_subprocess(arga, argb, iterations)