There is an existing close_fds parameter to the subprocess.Popen() constructor that prevents FDs being copied to the child process on UNIX. This patch makes that parameter also work on Windows (with a caveat). Setting this parameter on Windows was explicitly prohibited by the code, because it prevents redirecting stdin/stdout/stderr. However, the check is too restrictive; it is perfectly reasonable to set this flag if you are not redirecting anything. That is what this patch does. The behaviour is unchanged if you are on Windows, set this flag, and simultaneously try to redirect stdin/stdout/stderr: the call will fail with an exception. This patch is against Python SVN trunk. Kind regards, Jon Foster
I've been reading the general discussion on python-dev about patches needing documentation and tests. So here's an updated patch that includes docs and tests. File Added: subprocess_win32_close_handles_2.patch