Redirecting the output from sys.stdout

Oleg Broytmann phd at phd.russ.ru
Tue Apr 11 06:15:38 EDT 2000


On Tue, 11 Apr 2000, Pieter Claerhout wrote:
> Any examples on how to use the popen of the os module? Never used it before.

import os, string
pipe = os.popen("dir /w", 'r') # Open pipe for reading

lines = []
while 1:
   line = pipe.readline()
   if not line: break # EOF

   lines.append(line)

print string.join(lines, '') # Every line already contains newline, not need it here

Oleg.
---- 
    Oleg Broytmann    http://members.xoom.com/phd2.1/    phd2 at earthling.net
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list