How do I return binary data from a python CGI called from CGIHTTPServer?

Boyd Roberts boyd at insultant.net
Wed Jun 6 07:14:25 EDT 2001


"D-Man" <dsh8290 at rit.edu> a écrit dans le message news: mailman.991771931.11834.python-list at python.org...
> In MS-DOS terminals ctrl-z is used to indicate that you want to close
> the input stream (EOF).  On Unix terminals it is ctrl-d instead.

ctrl-d is only interpretted by the unix tty driver.  it has no
meaning anywhere else.  it means end of input stream and this
can occur multiply on ttys.

there are three cases:

    1. nothing in the tty's input queue
    2. some number of chars in tty's input queue
    3. the tty is in 'raw' mode

1 and 2 are really the same case because the ctrl-d tells the tty
driver to send up what's in the input queue so that the process
reading the tty gets the characters and the number of characters.

case 3 just hands up the characters as they are typed, so you
_could_ read a ctrl-d -- it does not mean end of file.  'raw'
mode is complicated by how braindamaged the tty driver is.

on unix, when a process calls read _in all cases_ (not just ttys) a
return of a 0 count indicates end of file.

> I think that the problem must be the sub-process thinks it is writing to
> a tty rather than a regular file, and thus is closing the output when
> you try and write ctrl-z.

you might be heading in the right direction, but you've got it around the
wrong way.  some braindamaged process reads the ctrl-z and treats that
as end of file.  or maybe you said that there are m < n bytes in the
data stream and at m bytes (instead of n) the reader says 'ok, end of file'.

lesson: in-band signaling is a sin.






More information about the Python-list mailing list