Search code examples
pythonc++data-transfer

How to send python list to C++ application awaiting input?


I am writing a python script that generates a list of integers and is supposed to send this list to a concurrently running C++ program that is constantly awaiting input. What is a quick and painless way to design the link between these two languages?

I have considered possibilities such as:

  • writing the python result to a file, while listening for file updates in C++ and loading it as soon as new data is available.
  • using python pexpect package and including a command line interface in the C++ program, so that it receives the data through cin.

Both above possibilities seem a bit too hacky to me. Are there better options, which would not require to become an expert in C++ library coding for python?


Solution

  • You could set up a Socket and an OutputStream in the python app to send the data, and another Socket and an InputStream in the C++ program to receive the data.