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

D-Man dsh8290 at rit.edu
Tue Jun 5 16:11:57 EDT 2001


On Tue, Jun 05, 2001 at 12:30:58PM -0700, Mark Wright wrote:
| "Alex Martelli" <aleaxit at yahoo.com> wrote in message news:<9f96kb01mq8 at enews1.newsguy.com>...
| > "Mark Wright" <mwright at pro-ns.net> wrote in message
| > news:f9ff3f62.0106011427.6243e5e9 at posting.google.com...
| >     ...
| > > But my original problem/question remains: how does a CGI program
| > > return binary data on windows?  Is it even possible?  The problem is
| > 
| > python.exe must be run with option -u, to have binary standard input
| > and output streams, rather than text ones as it has by default.
| 
| This works correctly for 0x0a, but it still gets upset about 0x1a -
| a.k.a. ctrl-Z, a.k.a. end of file.  If there's a ctrl-z in the output
| of my CGI script CGIHTTPServer truncates the data.

When I check 'man ascii' there is no EOF character.  End-of-file is a
condition, not a character, that is then simulated with a character
when the input is a terminal because terminals have an "endless" flow
of data.

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.  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.

How is the sub-process started?  What is the command for the
sub-process?  I don't know the details of Win32 process forking, but
if you are using a *nix system you will have to change 'python' to
'python -u' when you exec in the child.  (Or just adjust the string
passed to popen)

HTH,
-D





More information about the Python-list mailing list