I have the following code:
processes = []
for i in range(len(someList)):
processes.append(subprocess.Popen(["someExe"], creationflags = subprocess.CREATE_NEW_CONSOLE, stdin=subprocess.PIPE, stdout=subprocess.PIPE))
for i in range(len(processes)):
output = processes[i].communicate()[0].decode("utf-8").replace("\r\n","\n")
print(output)
I have an executable File which I need to execute in parallel (single execution of the .exe takes around 1 minute) and fetch the output from. If I execute the code as above, the subprocceses will open each in a new (empty) window, but for some reason they terminate consecutively (the first window clses after 1 minute, the second after 2, ...).
If I omit the stdout=subprocess.PIPE
the sub-windows open, and they actually terminate in parallel. Obviously the output is now printed in the respective window and fetching the output in the python script does not work anymore.
So my question is why this is the case and how can I get the best of both worlds (have them actually run in parallel and piping the output into python)