donut
donut

Reputation: 636

Calling a c++ file from Python

I have a Python code and, after running all the stuff in it, I want it to simply run a c++ file I have in the same directory. I read about Cython and BoostPython, but I don't think it is what I need (I could be wrong, obviously). I don't want to call functions, simply run the c++ algorithm. Is there an easy way to do it?

Upvotes: 0

Views: 294

Answers (1)

Doron Shevach
Doron Shevach

Reputation: 153

You can try open it as a subprocess in your script like this:

import subprocess
subprocess.call(["g++", "hello_world.cpp"])
tmp=subprocess.call("./a.out")
print("printing result")
print(tmp)

Upvotes: 6

Related Questions