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, kmeyer, paul.moore, socketpair, steve.dower, tim.golden, zach.ware
Date 2021-02-25.14:05:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614261907.69.0.355327667206.issue28654@roundup.psfhosted.org>
In-reply-to
Content
Here's an example of how to change the isatty() method in Modules/_io/fileio.c to check for a console in Windows:

    _io_FileIO_isatty_impl(fileio *self)
    {
        long res;

        if (self->fd < 0)
            return err_closed();
        Py_BEGIN_ALLOW_THREADS
        _Py_BEGIN_SUPPRESS_IPH
        res = isatty(self->fd);
    #ifdef MS_WINDOWS
        if (res) {
            DWORD mode;
            HANDLE h = (HANDLE)_get_osfhandle(self->fd);
            // It's a console if GetConsoleMode succeeds or if the last error
            // isn't ERROR_INVALID_HANDLE. e.g., if 'con' is opened with 'w'
            // mode, the error is ERROR_ACCESS_DENIED.
            res = GetConsoleMode(h, &mode) ||
                    GetLastError() != ERROR_INVALID_HANDLE;
        }
    #endif
        _Py_END_SUPPRESS_IPH
        Py_END_ALLOW_THREADS
        return PyBool_FromLong(res);
    }
History
Date User Action Args
2021-02-25 14:05:07eryksunsetrecipients: + eryksun, paul.moore, tim.golden, socketpair, zach.ware, steve.dower, kmeyer
2021-02-25 14:05:07eryksunsetmessageid: <1614261907.69.0.355327667206.issue28654@roundup.psfhosted.org>
2021-02-25 14:05:07eryksunlinkissue28654 messages
2021-02-25 14:05:07eryksuncreate