how do i run another script from my python script

N

nephish

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
 
S

Steve Holden

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
 
?

=?ISO-8859-1?Q?Daniel_Sch=FCle?=

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
.... 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"
....not there
not there
not there
not there
not there
not there
not there
not there
not there
not there
not there


hth, Daniel
 
M

Mike Meyer

Daniel Schüle said:
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
 
N

nephish

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top