Question

Before simply answering "use SWIG" or "just write it to a file on disk" read this:

I have a C++ client/server program. The client requests data from the server.

The server generates data and calls various routines to check the data. If all the data is correct, it sends the data via socket to the client.

What I'd like to do is take this raw data (say it was a String type data) and replace my "various routines" with python programs.

To do this, the raw data will be passed to the python programs to be parsed and checked, then they will need to return a pass/fail value to the C++ server.

Any ideas?

Was it helpful?

Solution

That's quite backwards from the normal way of doing things, isn't it!

You have two main options:

  1. Keep the Python scripts as they are, run them using fork()/exec() or whatever is appropriate to your platform, and parse their output in C++;
  2. Use CPython's well-documented API to embed it in your C++ program, and invoke the scripts that way.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top