Redirection problem.

Thaddeus L. Olczyk olczyk at interaccess.com
Wed Sep 13 17:34:56 EDT 2000


I'm having some problems with a simple redirection problem.
I want to write a function call it DoIt that executes a command
in a seperate process, and returns an error status when done.
I also want it to print to stdout the combination of what is written
in to stdout and stderr by the process.

For example:

if not DoIt("ls -R *"):
      print "Exited with error."
else:
     print "Exited with Success."

When executed the output ( sans stuff after # which are my comments
here) should look like:

dir1/f1   # normal listing
dir1/f2   # normal listing
dir2: Permission denied # process doesn't have read permission on that
directory
f3
f4
Exited with Success. # At least I think it should exit with success.

The problem I have is controling the two outputs, and the return code.

for example:
if I try

sout=os.popen(line,'r',0)
while 1:
   b=sout.read(1)
   sys.stdout.write(b)
   if not b:
       return sout.close()

The problem is squeazing at three conditions in.
TIA



More information about the Python-list mailing list