diff -r 84d74eb7a341 Lib/subprocess.py --- a/Lib/subprocess.py Wed Aug 21 18:25:00 2013 +0200 +++ b/Lib/subprocess.py Thu Aug 22 23:20:40 2013 +0200 @@ -1247,16 +1247,17 @@ os.close(fd) closed.add(fd) - # Close all other fds, if asked for - if close_fds: - self._close_fds(but=errpipe_write) - if cwd is not None: os.chdir(cwd) if preexec_fn: preexec_fn() + # Close all other fds, if asked for - after + # preexec_fn(), which might open FDs + if close_fds: + self._close_fds(but=errpipe_write) + if env is None: os.execvp(executable, args) else: