close failed: [Errno 0] No error goes to stdout

Peter Hansen peter at engcorp.com
Sun Aug 28 12:45:33 EDT 2005


Yoav wrote:
> I use the following code to the console output:
> 
> def get_console(cmd):
>         try:
>                 p_in, p_out, p_err = os.popen3(cmd)
>         except:
>                 pass
>         out_str = ''
>         for obj in p_out:
>                 out_str = out_str + obj
>         for obj in p_err:
>                 out_str = out_str + obj
>         return out_str
> 
> 
> for some reason some exceptions (stderr outputs) are not captured by the 
> try method, and slip to the screen. Any one has any idea on how can 
> prevent from any output that I don't want to?
> The output I get on these exceptions is:
> close failed: [Errno 0] No error

What makes you think the errors are getting past the try/except?  Could 
they be printed by the program you are invoking with popen3() instead? 
What does "cmd" equal when you get this failure?

Maybe you are expecting that popen3() will somehow raise exceptions when 
the called program fails, exceptions which the except statement would 
catch.  That's not the case.

-Peter



More information about the Python-list mailing list