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

Mark Wright mwright at pro-ns.net
Wed Jun 6 16:06:53 EDT 2001


D-Man <dsh8290 at rit.edu> wrote in 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.  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)

This actually seems to be a bug in win32popen.  If I print out some
binary data with an embedded 0x1a, like this:

    #binaryprinter.py
    import sys
    sys.stdout.write('\n\x1a' + 'abcdefg')

I get the correct result when running this program from the command
line:

    # reader.py
    import sys
    print repr(sys.stdin.read())

    C:\tmp>python -u binaryprinter.py | python -u reader.py
    '\n\x1aabcdefg'

However, I get the wrong value when I do a win32pipe.popen(), like
this program:

    # opener.py
    import sys
    import win32pipe

    print repr(win32pipe.popen('python.exe -u
binaryprinter.py').read())

    C:\tmp>python -u opener.py
    '\n'

How do I report this?

Mark



More information about the Python-list mailing list