running c++ code from python

前端 未结 4 608
日久生厌
日久生厌 2021-02-06 05:39

I want to execute a code helloword.cpp which takes in some argument from console parses those arguments and then prints \"hello world\" in the console.

Now, I want to pa

4条回答
  •  情深已故
    2021-02-06 06:20

    How about passing whatever text you generate with Python into the standard input of your C++ program? Basically, you have to use Python's subprocess module to fire up the C++ program and dump the text into its standard output.

    In case that your C++ program is required to be running separately in the background, you could try another form of interprocess communication, like unix domain sockets.

    Using boost::python is also an option, but it might be a little more difficult to deal with.

提交回复
热议问题