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

Y

Yoav

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


thanks.
 
P

Peter Hansen

Yoav said:
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
 
Y

Yoav

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 said:
Yoav said:
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
 
P

Peter Hansen

(Please don't top-post. It makes quoting difficult and it's hard for
people to follow the conversation.)
I run a Java command line program. The point is, that it's not the
program that output this error message for sure.

Okay. Since you don't provide any proof, we'll have to take you at your
word.

In that case, please provide the *complete traceback*, cut and pasted
from your console window. Don't just retype the error message.
Generally people leave out crucial information when they do that. The
traceback (which Python will always print when it raises an exception)
shows the failing line of code and the stack trace. With it we can help
you troubleshoot the problem. Without it, you haven't provided enough
information yet for anyone to do more than guess.

-Peter
 
S

Steve Holden

Yoav said:
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?
It would be helpful if you could verify your theory by running the
program from the command line with standard AND error output
redirection, verifying that no output at all apears on the console when
you type

cmd > /tmp/stdout 2>/tmp/stderr

You are correct in supposing that popen3 is supposed to trap all stdout
and stderr output.

regards
Steve
 
Y

Yoav

Steve said:
It would be helpful if you could verify your theory by running the
program from the command line with standard AND error output
redirection, verifying that no output at all apears on the console when
you type

cmd > /tmp/stdout 2>/tmp/stderr

You are correct in supposing that popen3 is supposed to trap all stdout
and stderr output.

regards
Steve

Thank you all for your help.
I managed to get rid of it, and I have this theory which I want to hear
your opinion about it:
It seems like it happened because I didn't bother to close the files
resulting from os.popen3(), and left Python to close them on it own. the
STDERR file wasn't always created, and therefore when Python tried to
close it, it generated an error. I thought that Python has better
abilities at closing files on its own, but I guess I was wrong. So my
conclusion is that whenever I open a file it MY job to close it. Again,
thank you all, you have been a great help. So now I am closing it with a
"try:... except: pass".

Thanks,

Yoav.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top