#!/usr/bin/env python
import sys
import subprocess
import os
import threading
import Queue

def create_process(args, file):
    process_msg = ''
    for arg in args:
        process_msg += arg + " "
    task = subprocess.Popen(args, stdout=file)
    return task
    
if __name__ == '__main__':
    args = sys.argv[2:]
    print "running '" + " ".join(args) + "' "+sys.argv[1]+" times"
    times = int(sys.argv[1])
    processes = []
    for i in xrange(times):
        f = os.tmpfile()
        p = create_process(args, f)
        processes.append((p, f))

    for p, f in processes:
        p.wait()
        f.seek(0)
        print f.read()
        f.close()
