|
Jorey Bump
list at joreybump.com
Wed Oct 4 08:58:44 EDT 2006
Ronald Levine wrote:
> I want my Python script, running under mod_python/publisher, to be
> able to invoke disk-resident C programs using os.popen, etc. , and
> receive their stdout, etc. It does not seem to be working for me. Are
> there some fundamental restrictions that preclude my plan?
Here's what I do when I need to read stdout & stderr combined:
import os
def index():
# os.popen4 combines stdout & stderr for reading
w, r = os.popen4('du -sh /tmp')
response = r.readlines()
r.close()
w.close()
return ''.join(response)
If you don't want to include stderr, use os.popen2. If you want it in a
separate object, use os.popen3 (w, r, e = os.popen3('command')).
|