ok, problem solved (well, partly - at least as much as I need it to be).

status = os.system('ps') doesn't set status equal to the output text, it sets it to the return of the call (in this case '0'). What I really want to do is

status = os.popen('ps').read()
print status

which works fine. However, why the first version confused the web server I don't know, I guess the output from ps went somewhere it wasn't supposed to.

nik

Nik wrote:
no luck I'm afraid.

Also, to make it even more annoying, omitting the os call and going for

#!/usr/bin/python

import cgitb; cgitb.enable()

print "Content-type: text/plain\n\n"
import os

status =   """PID TTY          TIME CMD
3649 pts0     00:00:00 su
3652 pts0     00:00:00 bash
5197 pts0     00:00:00 ps
"""
print status


works fine.

I've already half a dozen other scripts happily querying a database but this is the first one to have an error outside the usual brain fart stuff.

nik

Kent Johnson wrote:

Nik wrote:

hi,

I'm trying to write a python cgi script that can control certain processes on my server, but I'm having some trouble.
The script is;


#!/usr/bin/python

import cgitb; cgitb.enable()

print "Content-type: text/plain\n\n"



You may need explicit \r\n here, I'm not sure:

print "Content-type: text/plain\r\n\r\n"

Kent

import os
cmd = "/bin/ps"
status = os.system(cmd)
print status

which seems straight forward, but I get a server error, and
malformed header from script. Bad header= PID TTY TIME CMD:
appears in the apache logs. The PID TTY etc indicates it's getting the ps response, but why won't it display (even with text/plain)?


Ultimately I'll have the content type as html, and I'm going to preprocess the output of ps so it probably won't cause any problems, but I just don't understand why this isn't working in its simple form?

btw, the final idea is to list the processes corresponding to a certain name, and allow users to stop them or create new ones. I'm assuming this should be do-able?

nik
_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


_______________________________________________ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to