473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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.
Aug 28 '05 #1
5 3945
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
Aug 28 '05 #2
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

Aug 29 '05 #3
(Please don't top-post. It makes quoting difficult and it's hard for
people to follow the conversation.)

Yoav wrote:
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
Aug 29 '05 #4
Yoav wrote:
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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Aug 29 '05 #5
Steve Holden wrote:
Yoav wrote:
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


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.
Aug 30 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Bryan | last post by:
i'm curious to know how others handle the closing of files. i seem to always end up with this pattern even though i rarely see others do it. f1 = file('file1') try: # process f1 finally:...
0
by: Chris Jankowski | last post by:
I am trying to print an image file to a network printer and getting the following error. This is a Windows based system, using a network printer. Any ideas. Error Message: cannot print image...
1
by: Yoav | last post by:
I am using os.popen3 to call a console process and get its output and stderr. However on Win32 (and not OS X) I also get the Errno message. It's printed to the screen, which I wish to keep clean....
5
by: Craig Stratton | last post by:
Hi, cobalt 2.2.16 psql 7.2.3 DBI 1.32 I get this error, as in subject:- pqReadData() -- read() failed: errno=32 and then followed by this pqReadData() -- backend closed the channel...
2
by: RoSsIaCrIiLoIA | last post by:
Is it good the use of va_arg? ____________________ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <errno.h> unsigned gcd_my(unsigned a, unsigned b) {unsigned t;
4
by: CSN | last post by:
At startup this appears in the log: WARNING: dup(0) failed after 3195 successes: Bad file descriptor What does it mean? __________________________________________________
8
by: Atanas Banov | last post by:
i ran onto this weirdness today: seems like close() on popen-ed (pseudo)file fails miserably with exception instead of returning exit code, when said exit code is -1. here is the simplest...
19
by: empriser | last post by:
FILE *fp; fp = fopen( ... ) fclose( fp ). How do I know if fp has been fclose. I know can set fp to NULL after fclose it, then check fp's value to solve the problem. But, if there have...
5
by: Joakim Hove | last post by:
Hello, I have written a program in C; this programs uses an external proprietary library. When calling a certain function in the external library, the particular function writes a message to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.