Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 67927) +++ Modules/posixmodule.c (working copy) @@ -6496,8 +6496,13 @@ HANDLE read, write; int read_fd, write_fd; BOOL ok; + SECURITY_ATTRIBUTES saAttr; + + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; Py_BEGIN_ALLOW_THREADS - ok = CreatePipe(&read, &write, NULL, 0); + ok = CreatePipe(&read, &write, &saAttr, 0); Py_END_ALLOW_THREADS if (!ok) return win32_error("CreatePipe", NULL); Index: Lib/test/test_os.py =================================================================== --- Lib/test/test_os.py (revision 67927) +++ Lib/test/test_os.py (working copy) @@ -511,6 +511,36 @@ except NotImplementedError: pass +# this function runs in a subprocess +def child_test_pipe(r): + if sys.platform == 'win32': + import msvcrt + r = msvcrt.open_osfhandle(r, 0) + if os.read(r, 5)=='abcde': + sys.exit(0) + else: + sys.exit(10) + +class PipeTests(unittest.TestCase): + def test_pipe(self): + self.r, self.w = r, w = os.pipe() + os.write(w, 'abcde') + os.close(w) + if sys.platform == 'win32': + import msvcrt + r = msvcrt.get_osfhandle(r) + thisdir, thisfile = os.path.split(os.path.abspath(__file__)) + thismodule = os.path.splitext(thisfile)[0] + import subprocess + ret = subprocess.call([ + sys.executable, + "-c", + "from %s import child_test_pipe;child_test_pipe(%d)" % (thismodule, r), + ], + cwd=thisdir) + os.close(self.r) + self.assertEqual(ret, 0) + class Win32ErrorTests(unittest.TestCase): def test_rename(self): self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak") @@ -547,6 +577,7 @@ MakedirTests, DevNullTests, URandomTests, + PipeTests, Win32ErrorTests ) Index: Doc/library/os.rst =================================================================== --- Doc/library/os.rst (revision 67927) +++ Doc/library/os.rst (working copy) @@ -631,7 +631,10 @@ .. function:: pipe() Create a pipe. Return a pair of file descriptors ``(r, w)`` usable for reading - and writing, respectively. Availability: Unix, Windows. + and writing, respectively. On Unix, subprocesses inherit those file descriptors; + on Windows, their associated file handles are inheritable. (To convert file + descriptors into file handles and viceversa, use the msvcrt module.) + Availability: Unix, Windows. .. function:: read(fd, n)