|  | execute another python script |  | |
| | | Alexandru Mosoi |  |
| Posted: Mon Aug 18, 2008 8:27 am Post subject: execute another python script |  |
how do I execute another python script under a different process? I want the script to be run using the same interpretoer as the one running current script. I tried using os.execlp but I don't know how to get the name/path of the interpreter. |
| |
| | | Fredrik Lundh |  |
| Posted: Mon Aug 18, 2008 8:27 am Post subject: Re: execute another python script |  |
Alexandru Mosoi wrote:
| Quote: | how do I execute another python script under a different process? I want the script to be run using the same interpretoer as the one running current script. I tried using os.execlp but I don't know how to get the name/path of the interpreter.
import sys, subprocess subprocess.call([sys.executable, "-c", "print 'hello'"]) hello |
0
If Python is embedded in another program, it's unspecified whether sys.executable refers to the program or a compatible Python interpreter (see the python-dev archives for discussions), but the above should work in all cases if you're using a stand-alone interpreter.
</F> |
| |
| | | Alexandru Mosoi |  |
| Posted: Mon Aug 18, 2008 9:28 am Post subject: Re: execute another python script |  |
On Aug 18, 11:34 am, Fredrik Lundh <fred...@pythonware.com> wrote:
| Quote: | >>> import sys, subprocess >>> subprocess.call([sys.executable, "-c", "print 'hello'"]) hello 0
|
10x . exactly what I was looking for. |
| |
|
|