I have a python program running a c++ program as an executable. the c++ program is printing a few prints with std::cout and after it prints a few printing with printf. when I run the program using regular Popen I see all the printing on the output terminal, but when I use stderr=subprocess.STDOUT,stdout=subprocess.PIPE in the Popen command and after killing program I print the stdout, it's missing the printf output. I tried adding fflush(stdout); in my c++ program and it fixed the issue, but I want to find a way to fix the python script and not the c++ program. How can I fix this issue?
os.system("taskkill /im program.exe /F")
os.chdir(PROGRAM_PATH)
proc = subprocess.Popen(["program.exe", COM ,FILE],stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
time.sleep(3)
os.system("taskkill /im program.exe /F")
output = proc.stdout.readlines()
for line in output:
print(line)