Index: python3/Lib/test/test_subprocess.py =================================================================== --- python3.orig/Lib/test/test_subprocess.py +++ python3/Lib/test/test_subprocess.py @@ -621,6 +621,16 @@ class ProcessTestCase(BaseTestCase): self.assertFalse(os.path.exists(ofname)) self.assertFalse(os.path.exists(efname)) + def test_inouterr_fileobj(self): + # stdin, stdout and stderr are all set to a /dev/null file object + devnull = os.open(os.devnull, os.O_RDWR) + p = subprocess.Popen([sys.executable, "-c", 'import sys; sys.exit(0)'], + stdin = devnull, + stdout = devnull, + stderr = devnull) + p.wait() + self.assertEqual(p.returncode, 0) + # context manager class _SuppressCoreFiles(object): Index: python3/Modules/_posixsubprocess.c =================================================================== --- python3.orig/Modules/_posixsubprocess.c +++ python3/Modules/_posixsubprocess.c @@ -99,10 +99,10 @@ static void child_exec(char *const exec_ if (p2cread > 2) { POSIX_CALL(close(p2cread)); } - if (c2pwrite > 2) { + if (c2pwrite != p2cread && c2pwrite > 2) { POSIX_CALL(close(c2pwrite)); } - if (errwrite != c2pwrite && errwrite > 2) { + if (errwrite != p2cread && errwrite != c2pwrite && errwrite > 2) { POSIX_CALL(close(errwrite)); }