diff --git a/Lib/subprocess.py b/Lib/subprocess.py index c02fb52..98a25b3 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1112,8 +1112,14 @@ class Popen(object): if fd >= start_fd: os.closerange(start_fd, fd) start_fd = fd + 1 - if start_fd <= MAXFD: - os.closerange(start_fd, MAXFD) + maxfd = MAXFD + try: + maxfd = os.dup(0) + 1 + except: + pass + + if start_fd <= maxfd: + os.closerange(start_fd, maxfd) def _execute_child(self, args, executable, preexec_fn, close_fds,