0

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?

2
  • Please fix the indentation. Commented Jan 7, 2013 at 11:26
  • Maybe you need to wait for the subprocess' running is finished. Add process.communicate() before print "{ans:12}" Commented Jan 7, 2013 at 14:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i do see the output on my browser though..It's just that if I run the script from my browser by invoking POST to it the process doesn't start even though it appears to invoke the popen()
I will check the permissions issue though :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.