This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-03-06.01:58:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614995889.38.0.729191122852.issue43414@roundup.psfhosted.org>
In-reply-to
Content
Currently os.get_terminal_size() is hard coded to use the process standard handles in Windows. The function, however, is intended for arbitrary file descriptors, so should not be limited as follows:

    >>> f = open('conout$', 'w')
    >>> os.get_terminal_size(f.fileno())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: bad file descriptor

This is a simple fix. Rewrite it to use _get_osfhandle(). For example:

#ifdef TERMSIZE_USE_CONIO
    {
        HANDLE handle;
        CONSOLE_SCREEN_BUFFER_INFO csbi;

        _Py_BEGIN_SUPPRESS_IPH
        handle = (HANDLE)_get_osfhandle(fd);
        _Py_END_SUPPRESS_IPH
        if (handle == INVALID_HANDLE_VALUE)
            return PyErr_SetFromErrno(PyExc_OSError);

        if (!GetConsoleScreenBufferInfo(handle, &csbi))
            return PyErr_SetFromWindowsErr(0);

        columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
        lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
    }
#endif /* TERMSIZE_USE_CONIO */
History
Date User Action Args
2021-03-06 01:58:09eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower
2021-03-06 01:58:09eryksunsetmessageid: <1614995889.38.0.729191122852.issue43414@roundup.psfhosted.org>
2021-03-06 01:58:09eryksunlinkissue43414 messages
2021-03-06 01:58:09eryksuncreate