Windows binary stdin goes EOF after \x1a character

Discussion in 'Python' started by Dan, Oct 15, 2010.

  1. Dan

    Dan Guest

    I am writing a Windows program in Python 3.1.2 that reads binary data
    from stdin. Whenever it hits a \x1a character, stdin goes EOF and no
    more data can be read. A short program that exhibits this problem is:

    #listing of main.pyw
    import sys
    def go():

    The program is run as "pythonw.exe main.pyw"

    When fed with a block of bytes equivalent to "bytes(range(1,255))",
    the following output is observed...


    ....and according to the documentation, the empty bytes object means

    I wrote an equivalent program in C++ using the win32 ReadFile() call,
    and it read all 255 bytes just fine. What am I doing wrong with the
    python code?

    I am using Erlang to launch the Python program as a subprocess. The
    Erlang fragment that launches this and sends the data is:

    Port=open_port( {spawn_executable, "c:/Python31/pythonw.exe"},
    [{args, ["c:/iotest/main.pyw"]}]),
    Port ! {self(),{command,lists:seq(1,255)}},

    Dan, Oct 15, 2010
    1. Advertisements

  2. Dan

    Neil Cerutti Guest

    stdin is not in binary mode. Try invoking with -u option.
    Neil Cerutti, Oct 15, 2010
    1. Advertisements

  3. Dan

    Dan Guest

    That worked, thanks!
    Dan, Oct 15, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.