My problem is very similar to the problems described here and here with one thing not being covered: Assume, that I have an external longrunning.exe
on windows, and I'm calling that with subprocess.Popen()
. My exe now prints some commands and after some time, it gets into a loopback-mode and waits for input. When that happens, it outputs a single dot every second in the windows command prompt. It does put the subsequent dots on the same line, whereas all output before that is on its own line. I seem to be able to catch all output before that, but I cannot get this output, probably to some buffering going on(?). How can I get this output in my python console? Relevant code as below:
import subprocess
import sys
cmd = 'long_running.exe'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in iter(p.stdout.readline, b''):
sys.stdout.write(line)