[Tutor] pstree cgi-script
dyoo at hkn.eecs.berkeley.edu
Wed Jun 16 14:33:22 EDT 2004
On Tue, 15 Jun 2004, Chad Crabtree wrote:
> --- Conrad Gavin <gubbs at fudo.org> wrote:
> > Hi there.
> > I'm trying to write a simple little cgi-script that executes pstree
> > and
> > echos/prints the output to the webpage ..
> > Clearly I am doing it wrong, as it will not work.
> > Here's my code:
> > #!/usr/bin/python
> > import os
> > cmd = "pstree"
> > status = os.system(cmd)
> > print "Status:", status
> Ok this is an easy one. I also had this problem at first with cgi.
> you need to put
> print "text/plain/n/n"
> The two caraiage returns are important. There you go good luck
Small correction: this should really be:
print "Content-type: text/plain\n\n"
according to the CGI spec:
The reason why the Content-type header is important, and why it has to be
explicitely defined, is because CGI programs can generate more than
dynamic text content: CGI's can just as easily do things like dynamic
images. Page counters are one example of such a dynamic image CGI.
Hope this helps!
More information about the Tutor