[Tutor] using popen(n) to intercept stdout

Alan Gauld alan.gauld at freenet.co.uk
Fri Feb 17 00:07:31 CET 2006


Hi Tim,

> I now realize that to properly test this, I should use a command that
> returns legitimate data:
> I think the following gets me started:
> f = os.popen('ls *.py','r').read()
> now I have captured the output from 'ls *.py'.

You probably should consider using the Popen class in the new 
subprocess module. It makes all previous mechanisms (system, 
popen, commands, fork, execv etc) obsolescent.

There are basic instructions for using Popen to replace popen[n]  
etc in my new OS topic on the web site and the documentation 
gives some rather terse examples too...

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld





More information about the Tutor mailing list