[Tutor] pstree cgi-script

Conrad Gavin gubbs at fudo.org
Wed Jun 16 17:14:55 EDT 2004


On Wed, 2004-06-16 at 18:33, Danny Yoo wrote:
> 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
> 
> 
> Hi Chad,
> 
> Small correction: this should really be:
> 
> ###
> print "Content-type: text/plain\n\n"
> ###
> 
> according to the CGI spec:
> 
>     http://hoohoo.ncsa.uiuc.edu/cgi/out.html
> 
> 
> 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!
> 


My script still doesnt work. 

I sent an email to the list earlier in reply to Chad's original message
but it was not posted for some reason?

Anyway, here it is again .. 

<snip>

That doesnt seem to work either .. 
My code now:

#!/usr/bin/python

^

import os

print "text/plain/n/n"

cmd = "pstree"

^
status = os.system(cmd)

^
print status

I have tried placing print "text/plain/n/n" and the 'html'
varianteverywhere in the program it can feasably go (marked by the ^
symbol above), checked the permissions of the file etc. It still doesnt
work, the same error appears in the log:

[Wed Jun 16 13:15:14 2004] [error] [client 81.104.190.151] malformed
header from script. Bad header=init-+-5*[agetty]: hello.py

I am usingapache-2.0.49-r3, IDLE to write and save my script with and
python-2.3.4. I am then moving it as root to /var/www/localhost/cgi-bin
and chmod 755'ing it and then chmod +x _just_ to be absolutely certain.

It seems to be running tho, as the error is pretty indicative of the
line you suggested not being parsed or being ignored. 

This is why I asked really, I found a website that suggested using the
solution you offered but it didnt work .. 

I'm pretty much stumped. :(

Could you possibly place a working version on your server I could surf
too? At least then I would be absolutely certain it was a problem with
my end not the method .. 

I have confirmed my cgi works:

http://cpc3-nfds2-6-0-cust151.nott.cable.ntl.com/cgi-bin/test-cgi

Sorry to be a bother!

</snip>

Since Danny's message, I tried his suggestion also:

#!/usr/bin/python

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

import os

cmd = "pstree"

status = os.system(cmd)

print status

Oddly. It still does not work. 

I should add .. other scripts (which do not use the os module work just
fine). 

Any further advise? :(



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/tutor/attachments/20040616/a2327bf8/attachment.bin


More information about the Tutor mailing list