I want to make a python program who monitor DumpIt RAM dump. Whatever, figure out it's just a command line program who ask a Y/N question before do his job and exit.
I tried to do this with Python subprocess module but the read of stdout is blocking. I think because buffering of standard output.
When I launch a program who print something then exit, it works, but I want to get the live output while the process is running.
I have already tried the following:
live output from subprocess command
http://www.saltycrane.com/blog/2009/10/how-capture-stdout-in-real-time-python/
Here is the code on Windows 10 x64, Python 3.5
print("start dump")
proc = subprocess.Popen([os.getcwd() + "\Ressources\Dumper\DumpIt.exe"], bufsize=0, stdout=subprocess.PIPE)
print("dump launched")
#v1
for line in iter(proc.stdout.readline, ''):
sys.stdout.write(str(line))
#v2
# while True:
# line = proc.stdout.readline()
# sys.stdout.write(str(line))
# if line == "" and proc.poll() is not None:
# break
print("wait")
proc.wait()
print("done")
Output :
start dump
dump launched
sorry for bad English