2

I have a program in C++ that computes some ints. I want to "send" those ints from C++ to Python in real time. As the program in C++ is computing the numbers, I want to read them in Python.

What would be the best way to do this? I have seen some options but they all seem very complicated.

Rui Silva
  • 21
  • 4
  • 3
    The absolute simplest option IMO is to have your C++ program print its numbers to stdout, write a Python script that reads numbers from stdin, and pipe one to the other. It depends on whether you want to have the two compiled into a single binary, whether you want them to be able to run on different machines, etc. – Samwise May 04 '21 at 23:22
  • 1
    Some other options (which are indeed more complicated) are: Use a socket to send the data from the C++ program to the Python program, or alternatively embed the Python interpreter in the C++ program and have the C++ program run the Python script that way, or make a library out of the C++ code and write a wrapper so that the Python script can call the C++ code via function calls. – Jeremy Friesner May 05 '21 at 02:02
  • There are some good examples here of what you want to do: https://stackoverflow.com/questions/36748829/piping-binary-data-between-python-and-c – Fricative Melon May 05 '21 at 02:17
  • Thank you! Piping seems like the easiest way, I will try that – Rui Silva May 05 '21 at 10:15

0 Answers0