how do i run another script from my python script

Daniel Schüle uval at rz.uni-karlsruhe.de
Thu Oct 27 13:37:38 EDT 2005


Steve already answeared to your question, regaring PHP script

if this would be python script, you could run it by import'ing it

#a.py
print "in a"
------------

#b.py
import a	# prints "in a"
print "in b"
------------

and of course other solutions
import os
if os.fork()==0:
    os.execv("/bin/cmd_here", ["-blabla"])
else:
    # parent here

or maybe using threading

 >>> class FileWatcher(th.Thread):
...     def __init__(self, filename):
...             th.Thread.__init__(self)
...             self.filename = filename
...     def run(self):
...             import time
...             from os.path import exists
...             while not exists(self.filename):
...                     time.sleep(0.5)
...                     print "not there"
...
 >>> f = FileWatcher("/pool/xyz")
 >>> f.start()
 >>> not there
not there
not there
not there
not there
not there
not there
not there
not there
not there
not there
not there

 >>>


hth, Daniel




More information about the Python-list mailing list