Message387673
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);
} |
|
Date |
User |
Action |
Args |
2021-02-25 14:05:07 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, socketpair, zach.ware, steve.dower, kmeyer |
2021-02-25 14:05:07 | eryksun | set | messageid: <1614261907.69.0.355327667206.issue28654@roundup.psfhosted.org> |
2021-02-25 14:05:07 | eryksun | link | issue28654 messages |
2021-02-25 14:05:07 | eryksun | create | |
|