By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

how do i run another script from my python script

P: n/a
hey there all,
i have been looking for a way to run a php command line script from my
python script.

here is what i want to do:

if x = 4:
execute php4 testin.php
else:
execute php4 testout.php

and i also need the script to wait untill the php4 script is done
(which i think is the default ) before continuing to run.

i know this is possible, but how?
thanks

Oct 27 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ne*****@xit.net wrote:
hey there all,
i have been looking for a way to run a php command line script from my
python script.

here is what i want to do:

if x = 4:
execute php4 testin.php
else:
execute php4 testout.php

and i also need the script to wait untill the php4 script is done
(which i think is the default ) before continuing to run.

i know this is possible, but how?
thanks

import os
if x = 4:
script = "testin.php"
else:
script = "testout.php"
os.system(script)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 27 '05 #2

P: n/a
man, thats just too easy.
thanks much !

Oct 27 '05 #3

P: n/a
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

Oct 27 '05 #4

P: n/a
Daniel Schüle <uv**@rz.uni-karlsruhe.de> writes:
Steve already answeared to your question, regaring PHP script
if this would be python script, you could run it by import'ing it
That's not very pythonic. Better is to provide a function in the
script to run it (say run), then run that in the script iff it's
the script is being executed:

if __name__ == '__main__':
run()

Then to use it from another script, you'd do something like:

import myscript
myscript.run()
or maybe using threading


Launching new threads as part of the import process is
*dangerous*. There are some nasty bugs lurking there that cause things
like your import never finishing. If you need to start a thread in a
module, the approach outlined above avoids those bugs.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Oct 27 '05 #5

P: n/a
well i know i dont want to do another thread, my program has six
running all the time.
whew. that can get nuts.
i mean, this will come to me easier later i am sure. But right now.....
simple is best.
thanks for all the suggestions, gents.
right now i am just doing a varient of Steves suggestion, and so far,
its working.

thanks again,
sk

Oct 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.