[New-bugs-announce] [issue17797] Visual C++ 11.0 reports fileno(stdin) == 0 for non-console program

Mateusz Loskot report at bugs.python.org
Fri Apr 19 14:18:32 CEST 2013

New submission from Mateusz Loskot:

In pythonrun.c, there is function initstdio() with the following test:

static int
    /* Set sys.stdin */
    fd = fileno(stdin);
    /* Under some conditions stdin, stdout and stderr may not be connected
     * and fileno() may point to an invalid file descriptor. For example
     * GUI apps don't have valid standard streams by default.
    if (fd < 0) {
        std = Py_None;
        goto error;
    else {

This function is fails for non-console applications (i.e. MFC) built using Visual C++ 11.0 (Visual Studio 2012), becasue **strangely**, fileno(stdin) == 0, so this test results in false and Python initialisation routines attempt to setup streams.

Apparently, fileno(stdin) return value has changed between Visual C++ 10.0 (VS 2010)
and 11.0. The VC++ 10.0 reports fileno(stdin) == -2.

components: IO, Interpreter Core
messages: 187351
nosy: mloskot
priority: normal
severity: normal
status: open
title: Visual C++ 11.0 reports fileno(stdin) == 0 for non-console program
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list