<div class="gmail_quote">On Tue, Jan 25, 2011 at 04:25, Geoff Bache <span dir="ltr"><<a href="mailto:geoff.bache@gmail.com">geoff.bache@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<br>
<br>
I have a Python process on Windows and would like to start a Python<br>
subprocess using the same interpreter. I wonder how to go about this?<br>
<br>
First, I tried the obvious<br>
<br>
subprocess.Popen([ sys.executable, "subproc.py", ... ])<br>
<br>
but that fails, because my process has a "native launcher", (i.e. C:<br>
\path\mylauncher.exe, which is just a wrapper around the Python<br>
program) and hence sys.executable returns this path instead of the<br>
interpreter location. It isn't appropriate to use the launcher for the<br>
subprocess.<br>
<br>
I also tried using sys.exec_prefix but there didn't seem to be any<br>
standard location for the interpreter under this directory in any<br>
case.<br>
<br>
I feel certain there must be some way to do this as it seems a rather<br>
basic thing somehow, can anyone give me a hint?<br>
<br>
Regards,<br>
Geoff Bache</blockquote><div><br></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">If </span><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">sys.executable doesn't work due to this "native launcher", you could try</span> something like this:</div>
<div><br></div><div><div>>>> import os</div><div>>>> import sys</div><div>>>> full_path = None</div><div>>>> for path in sys.path:</div><div>...     full = os.path.join(path, "python.exe")</div>
<div>...     if os.path.exists(full):</div><div>...             full_path = full</div><div>...</div><div>>>> full_path</div><div>'c:\\python31\\python.exe'</div></div><div></div></div>