Alon_T
Alon_T

Reputation: 1440

running a python script on server

i have a python script on the server

#!/usr/bin/env  python
import cgi
import cgitb; #cgitb.enable()
import sys, os
from subprocess import call
import time
import subprocess
form = cgi.FieldStorage()

component = form.getvalue('component')
command = form.getvalue('command')

success = True

print """Content-Type: text/html\n"""

if component=="Engine" and command=="Start":
    try:
         process = subprocess.Popen(['/usr/sbin/telepath','engine','start'], shell=False, stdout=subprocess.PIPE)
         print "{ans:12}" 
    except Exception, e:
         success = False
         print "{ans:0}"

When I run this script and add the component and command parameters to be "Engine" and "Start" respectively - it starts the process and prints to the shell

"""Content-Type: text/html\n"""
{ans:12}

but most importantly - it starts the process!

however, when I run the script by POSTing to it, it returns {ans:12} but does not run the process which was the whole intention in the first place. Any logical explanation?

Upvotes: 0

Views: 250

Answers (1)

Chris Seymour
Chris Seymour

Reputation: 85785

I suspect it's one of two things, firstly your process is probably running but your python code doesn't handle the output so do:

process = subprocess.Popen(['/usr/sbin/telepath','engine','start'], shell=False, stdout=subprocess.PIPE)
print process.stdout.read()

This is the most likely and explains why you see the output from the command line and not the browser, or secondly because the script is run through the browsers as the user apache and not with your userid check the permission for /usr/sbin/telepath.

Upvotes: 1

Related Questions