[Tutor] pstree cgi-script

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Jun 16 18:53:54 EDT 2004



On Wed, 16 Jun 2004, Conrad Gavin wrote:

> Btw did you test this script on your own apache before sending it to me?
> Did it work?

Good question.  No.  *grin*


I have tested the following version of the code:

######
#!/usr/bin/python
import sys
import os
import cgitb; cgitb.enable()

sys.stdout.write("Content-type: text/plain\n\n")
cmd = "/usr/bin/pstree"
status = os.popen(cmd).read()
print status
######


I can confirm that this works on my machine.

The major fix here is to use os.popen() instead of os.system().
os.system() returns the "errorlevel" of the program, not its standard
output.  os.popen() is probably what you want to use to capture the output
of other programs.


Good luck!




More information about the Tutor mailing list