I want to run a subprocess.Popen('echo 1; sleep 1; echo 1', shell=True, stdout=?)
in a way I would have the output appear (at run time) and also be able to save it into a PIPE or file.
So far I ran with proc = subprocess.Popen('echo 1; sleep 1; echo 1', shell=True, stdout=PIPE, stderr=PIPE)
giving me the 2nd requirement, and then I would print the result of out, err = proc.communicate()
, but using communicate
is blocking, and so, if the Popen
takes a long time, I can't show the output and that's unacceptable.
Can I somehow leave the stdout=
field empty (to enable console output) and also copy output to a PIPE?
Update. This is not the same as Python Popen: Write to stdout AND log file simultaneously because I want to be able to access the oputput during the run, and the solution there suggests accessing proc.stdout which is blocking until the end of the run.