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

Yoav yoav_artzi at il.vio.com
Mon Aug 29 10:22:52 CEST 2005


I run a Java command line program. The point is, that it's not the 
program that output this error message for sure. And I don't expect 
popen3() to catch and report errors. I just want to keep my screen 
output clean, and I expect popen3() to run the program and not let 
anything slip to the screen, after all as I understood it is supposed to 
capture STDERR and STDOUT, but maybe I didn' t understand it right (it's 
quite probable). Anyway anyway I can do such a thing?

Thanks.

Peter Hansen wrote:
> 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