TheKingLives TheKingLives -4 years ago 149
Linux Question

Pass data from a c++ program to a python program on linux

I have a c++ program that returns a value(the value changes constantly) and I would like to make a python program that takes the value that the c++ program returned and use it.
I would like to ask if there is any way to perform this task or anything at all that can help me in achieving this.
I want the two programs to be able to run simultaneously.

Ok lets assume the c++ program is the code below:

int main() {
int x = 1;
fprintf(stdout,"%d\n", x);
return 0;


How can I make a python program that takes the variable x as its input each time it cahnges.

Answer Source

You could use a pipe to forward your C++ program's stdout to your Python program's stdin:

./my_cpp_program.x | ./ 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download