I have a piece of C++ code that generates the data. I want to expose the data to Python. But it is not as trivial as it sounds...
Say this C++ compiles into binaries cppcode
. Because of the complicated way of the framework setup, I can only run the code as
./cppcode {command line arguments}
Inside cppcode it generates data that I want to access from Python. I know if I can somehow rewrites the program as
CppClass cpp;
cpp.run( args );
Then I can wrap up CppClass with Boost Python, build an instance, run with arguments, and access the data in generates.
But now that I can only run the code as ./cppcode {command line arguments}
I can't just call ./cppcode
from Python, because after ./cppcode finishes, its memory will be recollected by the system, and I can't see it from Python anymore. Is there a way to get around that?
I can think of: (1) let ./cppcode dump the data into the disk and let python read it. (2) dump the data to stdout and pipe into python script. But either way I have to do some string parsing in Python that could be slow. Is there a way to get around it?