Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how do i run another script from my python script

Reply
Thread Tools

how do i run another script from my python script

 
 
nephish@xit.net
Guest
Posts: n/a
 
      10-27-2005
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

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      10-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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/

 
Reply With Quote
 
 
 
 
nephish@xit.net
Guest
Posts: n/a
 
      10-27-2005
man, thats just too easy.
thanks much !

 
Reply With Quote
 
=?ISO-8859-1?Q?Daniel_Sch=FCle?=
Guest
Posts: n/a
 
      10-27-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

 
Reply With Quote
 
Mike Meyer
Guest
Posts: n/a
 
      10-27-2005
Daniel Schüle <(E-Mail Removed)-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 <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
nephish@xit.net
Guest
Posts: n/a
 
      10-28-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
run a script getting 4 arguments from another script souleymane yo Python 1 07-23-2011 12:19 AM
(How) Can you run another ruby script, from a ruby script? 3lionz Wexler Ruby 2 08-24-2010 04:27 AM
Run a python script as an exe and run a new process from it venutaurus539@gmail.com Python 9 02-27-2009 05:22 PM
executing a python script from another python script. sarmin kho Python 1 06-04-2004 01:12 PM



Advertisments