How to call python from C ++

I am a new Python fan. I tried calling a python script from C ++ like this (in Raspberry Pi).

std::string pythonCommand = "python Callee.py \""+a+"\" "+b;
int res = system(pythonCommand.c_str());

after launch i got this.

python: can't open file 'Callee.py': [Errno 2] No such file or directory

But I can run Callee.py with the command line successfully and both files are stored in the same directory.

What did I miss?

+4
source share
2 answers

You are probably using the python interpreter (and your command python Callee.py) in some weird directory (i.e. in some other directory than you expect).

You can use getcwd (3) before your call to system (3) to find out the current working directory.

chdir (2) ( system), - . ., , .

Linux

Python Interpreter; , Guile Lua.

+3

-

system("/work/test/pythonscript.sh")

script, python script.

, (c_string() "\ r" , )

+1

Source: https://habr.com/ru/post/1677838/


All Articles