self.addCleanup(os.close, fd2)
self.assertEqual(os.get_inheritable(fd2), False)
+ def test_dup_standard_stream(self):
+ fd = os.dup(1)
+ self.addCleanup(os.close, fd)
+ self.assertGreater(fd, 0)
+
@unittest.skipUnless(sys.platform == 'win32', 'win32-specific test')
def test_dup_nul(self):
# os.dup() was creating inheritable fds for character files.
flags = HANDLE_FLAG_INHERIT;
else
flags = 0;
- if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) {
+
+ /* This check can be removed once support for Windows 7 ends. */
+#define CONSOLE_PSEUDOHANDLE(handle) (((ULONG_PTR)(handle) & 0x3) == 0x3 && \
+ GetFileType(handle) == FILE_TYPE_CHAR)
+
+ if (!CONSOLE_PSEUDOHANDLE(handle) &&
+ !SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) {
if (raise)
PyErr_SetFromWindowsErr(0);
return -1;
}
+#undef CONSOLE_PSEUDOHANDLE
return 0;
#else