Get python executable full path from C++
<p>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 <code>PATH</code>. So, i would like to have a function <code>get_exec_path("python")</code> whick returns something like <code>C:\Python27\python.exe</code>. <code>C:\Python27\</code> is in my <code>PATH</code>.
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:</p>

<pre><code>std::system("start \"\" /WAIT python myscript.py --arg1 arg1 --arg2 arg2")
</code></pre>

<p>but this method shows command prompt window, I would like some kind of background work. For this purpose I used <code>CreateProcess</code> with second argument <code>"C:\Python27\python.exe myscript.py --arg1 arg1 --arg2 arg2"</code>. So, I need full path to python executable from <code>PATH</code> variable.</p>

<p>You're asking the wrong question.</p>

<p>Instead of trying to bypass the shell (and reinventing the <code>PATH</code> variable while doing so), <em>use it to your advantage</em> by passing the proper flags to <code>start</code> for hiding the command prompt window.</p>

<p>According to <a href="https://technet.microsoft.com/en-gb/library/bb491005.aspx" rel="nofollow">the documentation</a>, that's <code>/b</code>:</p>

<blockquote>
  <p>Starts an application without opening a new Command Prompt window.</p>
</blockquote>

python c++