[Python-Dev] OT: fdopen on Windows question

skip at pobox.com skip at pobox.com
Fri Oct 20 21:39:58 CEST 2006

Sorry for the off-topic post.  I figured someone here would know the answer
and I don't have access to Windows to check experimentally.

The ocrad program opens its input like so:

    if ( std::strcmp( infile_name, "-" ) == 0 )
        infile = stdin;
        infile = std::fopen( infile_name, "r" );

(SpamBayes is starting to use ocrad and PIL to extract text from image
spam).  Ocrad fails on Windows because the input file is opened in text
mode.  That "r" should be "rb".  What's not clear to me is whether we can do
anything about stdin.  Will this work:

    if ( std::strcmp( infile_name, "-" ) == 0 )
        infile = std::fdopen( std::fileno(stdin), "rb" );
        infile = std::fopen( infile_name, "rb" );

That is, can I change stdin from text to binary this way or is it destined
to always be in text mode?



More information about the Python-Dev mailing list