[Tutor] cgi with system calls

Nik mymailinglists at neuf.fr
Tue Dec 14 13:21:34 CET 2004


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"
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


More information about the Tutor mailing list