[mod_python] mod_python and os.system and os.popen

Martha Zimet zimet at manray.com
Fri Feb 22 18:34:04 EST 2008

I am attempting to call os.system and os.popen from within
a mod_python script and nothing happens. That is, the commands
perform no action. I am attempting to use os.system and os.popen
to execute wget, and I wonder if there any tricks that I am not
aware of. I have been googling and didn't find anything useful. 
Any assistance would be appreciated. 

Here is some code where 'update' is called from an HTML form. 
I have tried both os.system and os.popen with the same result.
I read about Popen, rather than os.popen, but that does not 
seem to exist in my implementation.

Thanks in advance.



from mod_python import apache
import cgi
import pg
from cgi import escape
from urllib import unquote
import sys
import os

def update(req):

    # The getfirst() method returns the value of the first field
    # with the name passed as the method argument
    host = req.form.getfirst('host', '')
    user = req.form.getfirst('user', '')
    password = req.form.getfirst('password', '')    

    # Escape the user input to avoid script injection attacks
    host = cgi.escape(host)
    user = cgi.escape(user)
    password = cgi.escape(password)

        output = ''
        command = "wget --user %s --password %s
http://%s/svn/backend/able1.0/db/db.sql" % (user, password, host)
        ouput = os.popen(command).read

    except Exception, e:
        r = sys.exc_info()
        generator = (str(x) for x in r)
        newstring = ''.join(generator)

More information about the Mod_python mailing list