execute another python script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexandru  Mosoi

    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

    #2
    Re: execute another python script

    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.ca ll([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>

    Comment

    • Alexandru  Mosoi

      #3
      Re: execute another python script

      On Aug 18, 11:34 am, Fredrik Lundh <fred...@python ware.comwrote:
       >>import sys, subprocess
       >>subprocess.ca ll([sys.executable, "-c", "print 'hello'"])
      hello
      0

      10x :). exactly what I was looking for.

      Comment

      Working...