0

I would like to be able to retrieve some results from C++ when I call a Python script using the following command:

    int nResult = PyRun_SimpleFileEx(PyFile_AsFile(pyFileObject), strScriptPath.GetBuffer(), 1);

The goal here is to be able to communicate between my Python script and my C++ code. I've seen some examples of code for when calling a Python function, but nothing concerning a whole script.

MasterMind
  • 379
  • 2
  • 17
  • 2
    I think you're going about this the wrong way. You're running a whole script to completion, so how would your C++ code get a chance to receive the value from the script? Most times, C++ code calls into a particular Python function and stores the result. – jeffknupp Mar 14 '13 at 14:51
  • 1
    If you don't have to run the *whole* script (and I can't imagine why you *would* have to), you can just create a Python function that returns the values you want your C++ program to have access to and call the Python code from C++. This is the typical way to access Python-generated data from C++. Otherwise you're just forking a script and reading stdout... – jeffknupp Mar 15 '13 at 18:36
  • The problem is I really need to execute the whole script, since I have no control over this script - it is created by the user of the software I'm working on. – MasterMind Mar 18 '13 at 16:43
  • Have you tried ZeroMQ for this task? – sidewaiise Oct 28 '16 at 15:50

0 Answers0