I'm creating a object and color detection robot. Here in this case, I'm using C++ to run the camera and process the image with openCV in C++, but before I run the Camera, I want the robot to move and do other activities for which I'm using python codes. So basically, I want to run a python code and then run the C++ code and then get back to the python code. How do I do it? Thanks a lot for reading. Please help me.

1 Answer 1


You may want to launch your C++ application via a subprocess, launched from python, then communicate with it using stdin/stdout. This way, both programm will run in parrallel (python needs to be launched first), avoiding the need to switch from one to the other.

Here is how to launch your subprocess:

import subprocess
mysubproc = subprocess.Popen('/myfolder/myprogram', 

then to pass some information from python to C++ :


And to read the result from the C++ program :

while True:
  line = mysubproc.stdout.readline()

This will work fine, unless you have to tranfer large amount of datas (i.e. images). In this case, I would write these data to a temporary file, then only pass the file location via stdin/stdout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.