I am trying to interact with an application using subprocess. I've created the process using Popen but I am not able to access the output stream without blocking the whole thread. Writing to the inputstream however seem to work fine (tested it using communicate, however I may not be able to use this later as I need real time data).
I have already tried putting the buffer to 1 but it doesnt seem to work.
I have noticed that sometimes if the process terminates, the output is flushed. I do believe that this issue may be caused by the fact that no flushing occurs (and that on closing, all the data gets recived at the same time) but I am not sure.
C code:
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: \n");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
Python code
import subprocess
p = subprocess.Popen("./a.out", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True, bufsize=1, close_fds=True)
print(p.stdout.read(1)) #This should read E but instead blocks the whole thread!