Newbie: Capture output of compile_dir

Becky Hehn chicken7373 at yahoo.com
Mon Jul 15 17:04:28 EDT 2002


In-Reply-To: <Pine.LNX.4.44L.0207152109490.1508-100000 at ods.pp.ru>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

Thanks for the response.  I tried the code you gave
me, but it didn't quite work like I wanted.  I created
a syntax error in my python file (left out a quotation
mark) and tried the code.  Below is the information
from my interpreter session:


>>> import sys
>>> from cStringIO import StringIO
>>> from compileall import compile_dir
>>> path='/home/hehn/test'
>>> orig_so = sys.stdout
>>> sys.stdout = captured = StringIO()
>>> compile_dir(path,force=1)
File "/home/hehn/test/me.py", line 2
Write('status)
Syntax Error:  invalid token
>>> sys.stdout = orig_so
>>> output = captured.getvalue()
>>> output
'Listing /home/hehn/test . . . Compiling
/home/hehn/test/me.py'


If an the prompt I just type the compile command, I
get all the output at once(see below).  I would like
the output variable to contain all this feedback from
the compile_dir command.  Not just the initial two
lines.  Any thoughts on what I did wrong?  Thank you
in advance.


>>> compile_dir(path,force=1)
Listing /home/hehn/test . . . 
Compiling /home/hehn/test/me.py . . . 
  File /home/hehn/test/me.py, line 2
  Write('status)
Syntax Error: invalid token
1





--- "Denis S. Otkidach" <ods at fep.ru> wrote:
> 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]
> 



__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com





More information about the Python-list mailing list