473,569 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i run another script from my python script

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
5 1978
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.ph p"
os.system(scrip t)

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
man, thats just too easy.
thanks much !

Oct 27 '05 #3
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.__ini t__(self)
.... self.filename = filename
.... def run(self):
.... import time
.... from os.path import exists
.... while not exists(self.fil ename):
.... 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
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.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Oct 27 '05 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4891
by: DeepBleu | last post by:
When one is using an HTML form via a web broswer, the user submits the form contents and these are passed to a CGI Python script on the web server. I need to write a client script that connects to a web site, runs a Python CGI script on the web server AND passes a string to the CGI Python script that the Python CGI script can...
6
2819
by: Paul Winkler | last post by:
This is driving me up the wall... any help would be MUCH appreciated. I have a module that I've whittled down into a 65-line script in an attempt to isolate the cause of the problem. (Real domain names have been removed in everything below.) SYNOPSIS: I have 2 target servers, at https://A.com and https://B.com. I have 2 clients, wget...
2
2014
by: Efrat Regev | last post by:
Hello, I'm a data-structures course TA trying to write a python CGI script for automatically compiling and testing students' projects. Unfortunately, I've run into some questions while writing this, which I couldn't solve with the various (and helpful) python-CGI documentation. (It's possible that I'm posting to the wrong group; if so, I'd...
10
3471
by: Noah | last post by:
I would like to package my main script and all the modules it imports into a single script that will run just as the collection would. It should not need to package standard Python lib modules -- just my local modules. This is not the same question that would be answered with py2exe or py2app. I don't need to package the script into a binary...
6
9910
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
9
3738
by: boris.smirnov | last post by:
Hi there, I have a problem with setting environment variable in my script that uses qt library. For this library I have to define a path to tell the script whre to find it. I have a script called "shrink_bs_070226" that looks like this: ********************************** import sys, re, glob, shutil import os
4
2082
by: dbee | last post by:
Right. I've got a really, really annoying/difficult/time consuming problem with my development environment. I'm using django to build a web app with paypal integration. My server is hosted remotely, and it is receiving IPN (payment notifications) POST requests from Paypal. I've checked on google and irc and this is my last shot at solving...
1
1740
by: michael.buonomo | last post by:
We have been using the Google recommended python script for about a year. We recently realized that the script was not crawling our sites url's, but just our folders which reside on the server. The python script seems to be designed for 'non database' sites, not a site which is using .asp, and has dynamic pages. We are an ecommerce site....
3
5443
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I would like for the python script to exit once the call has been made, without waiting for the shell script to finish. My question is: how do I call...
4
6176
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages generated are written to a log file. A project team working in the same company as me here would like to use this loading utility. They write UI...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.