I have a C++ executable which has the following lines of code in it
/* Do some calculations */
.
.
for (int i=0; i<someNumber; i++){
int inputData;
std::cin >> inputData;
std::cout<<"The data sent from Python is :: "<<inputData<<std::endl;
.
.
/* Do some more calculations with inputData */
}
and this is called in a loop. I want to call this executable in python subprocess like
p = Popen(['./executable'], shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
I could get the output from the executable using
p.server.stdout.read()
But I am not able to send data (integers) from python using
p.stdin.write(b'35')
Since cin
is called in a loop, the stdin.write
should also be called multiple times (in a loop). Is this above possible .. ?
Any hints and suggestion how I could do it ? Thanks in advance.