"print" strange with Sybase module
Erwin S. Andreasen
erwin at andreasen.com
Thu Jan 25 14:57:26 EST 2001
On Thu, 25 Jan 2001 13:04:10 +0100, Carsten Gaebler wrote:
>The following simple program (sqltest.py) returns about 20 lines of
>Sybase output when run as "./sqltest.py". But if I say
>
>./sqltest.py | tee /tmp/test.txt
>
>there is no output and test.txt is empty. What's going wrong? It's
>Sybase module 0.10 with Python 2.0.
Does your Python interpreter exit before the very end with some fatal error?
(do echo $? after you run the script without piping it to see the exit error
code, is it 0?).
You see, standard output which "print" prints to is line-buffered when
connected to a terminal (i.e. the buffer is flushed after each line). When it
is run through a pipe, it is block buffered (i.e. the buffer is flushed after
4096 bytes of output has been gathered).
If the program exits unexpectedly (sys.exit(1) or an exception is OK, but
os._exit(1) or a fatal signal isn't) these buffers will not be flushed.
I can't see a reason to why it would exit that way quietly, but unflushed
buffers are the first thing that comes to mind when seeing those symptoms.
PS: Any Python-users attending Linux Expo in Paris?
--
=======================================================================
<erwin at andreasen.com> Herlev, Denmark Software Designer
<URL:http://www.andreasen.org/> <*> LASAT^WEicon Networks
=======================================================================
More information about the Python-list
mailing list