I have an exectuable that if i run it with flags it starts a tool that generate messages all the time. When i try to run it with subprocess i get the output to the cmd and that is fine. The thing is that i want to take this messages and do something with them but for some reason the unbuffring method is not working and I'm not getting any message .
The following is the code that I tried :
p = subprocess.Popen(
["my_tool.exe","runMode","y","port","1234"],stdout=subprocess.PIPE,stderr=subprocess.STDOUT, bufsize=1)
To generate the output tried the folloing:
for line in p.stdout:
print("CUR", line)
and:
while p.poll() is None:
line = p.stdout.read(2)
print("Print:" + line)
and:
for line in iter(p.stdout.readline, b''):
print(line)
p.stdout.close()
Any idea why the code blocks on the stdout line alwayes ?
UPDATE:
For example if i have the following infinite program:
inf.py
import time
i = 0
while True:
time.sleep(0.5)
print(i)
i += 1
and the following code that runs it:
p = subprocess.Popen(r"C:\Python35\python.exe inf.py",
stdout=subprocess.PIPE, bufsize=1, universal_newlines=True)
and to generate the output I'm using one of the above methods , If i stop it using CTRL+ C it is alwayes stuck on this line:
File "C:\Python35\lib\encodings\cp1252.py", line 22, in decode
def decode(self, input, final=False):