I have a program, written in C++. I would like to get full path to python executable from it. For example, if I open Windows command prompt (cmd.exe) and type python, it use python executable from PATH
. So, i would like to have a function get_exec_path("python")
whick returns something like C:\Python27\python.exe
. C:\Python27\
is in my PATH
.
I need this for calling python scripts from C++ code. Embedding python in C++ is a bad idea for my purposes. I used to call it like this:
std::system("start \"\" /WAIT python myscript.py --arg1 arg1 --arg2 arg2")
but this method shows command prompt window, I would like some kind of background work. For this purpose I used CreateProcess
with second argument "C:\Python27\python.exe myscript.py --arg1 arg1 --arg2 arg2"
. So, I need full path to python executable from PATH
variable.