I am using the subprocess module to run binaries from python.
To capture the output produced by the binary, I am using:
proc = subprocess.Popen (command_args, shell=False, stdout=subprocess.PIPE)
out = proc.communicate()[0]
#print the output of the child process to stdout
print (out)
What this does is print the output of the process AFTER it has finished executing. Is there anyway I can print this output to stdout WHILE the program is executing? I really need to see what the output is because these programs can run for a long time.
Thanks for the help.
Basically you have 3 options: Use threading to read in another thread without blocking the main thread. select on stdout, stderr instead of communicate. This way you can read just when data is available and avoid blocking. Let a library solve this, twisted is a obvious choice.
– Argillaceous