tags:

views:

140

answers:

2

I setup a lighttpd server along with webpy and fastcgi. I am trying to simply run a python script everytime the wenpy app is accessed. Though it seems even when I give the normal python code to execute the script it does nothing. So Id like to be able to run this script, any idea would be helpful.

#!/usr/bin/env python

import web, os

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        os.system("python /srv/http/script/script.py")
        if not name:
            name = 'world'
        return "Running"

web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
if __name__ == "__main__":
    app.run()
+1  A: 

Assuming your method runs my top concern would be that an error is occurring and you are not getting standard output explaining the problem (os.system will get the return value, e.g. exit code). Python docs recommend replacing it with subprocess, I like to do this:

from subprocess import Popen, PIPE
proc = Popen('ls', shell=True, stdout=PIPE)
proc.wait()
proc.communicate()
Aea
All I get back from pipe is a -1, and the program is never ran.
Recursion
Have you tried printing out the command and running it directly? What about through a shell?-1 Implies a failure at some level.
Aea
Works just fine in a shell when I run it normally. Both the script im trying to run as well as the program above work fine. I just get the error when I try to run it while accessing the server.
Recursion
Only other thing I could think of is permissions.
Aea
A: 

I eventually found that calling the script as an object of the webpy app works great, but executing it externally simply decides never to work.

Recursion