execute another python script

Fredrik Lundh fredrik at pythonware.com
Mon Aug 18 04:34:52 EDT 2008


Alexandru Mosoi wrote:

> 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>




More information about the Python-list mailing list