Newbie: Capture output of compile_dir

Denis S. Otkidach ods at fep.ru
Mon Jul 15 13:11:36 EDT 2002


On Mon, 15 Jul 2002, Becky Hehn wrote:

BH>
BH> I want to be able to capture the output of compile_dir
BH> because I want to further process the output of this
BH> command.  It appears that compile_dir prints output to
BH> the screen rather than returning it to the caller.
BH> How do I capture the output of this command?  If I do
BH> something like:
BH> output=compile_dir(path)
BH> the output of compile_dir gets printed to the screen
BH> and the variable output just hold an integer.

import sys
from cStringIO import StringIO
orig_so = sys.stdout
sys.stdout = captured = StringIO()
compile_dir(path)
sys.stdout = orig_so
output = captured.getvalue()

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]
http://diveinto.python.ru/ [ru]






More information about the Python-list mailing list