Index: subprocess.py =================================================================== --- subprocess.py (revision 53295) +++ subprocess.py (working copy) @@ -717,6 +717,8 @@ def _make_inheritable(self, handle): """Return a duplicate of handle, which is inheritable""" + if not handle: + return None return DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), 0, 1, DUPLICATE_SAME_ACCESS) @@ -752,12 +754,19 @@ # Process startup details if startupinfo is None: startupinfo = STARTUPINFO() - if None not in (p2cread, c2pwrite, errwrite): - startupinfo.dwFlags |= STARTF_USESTDHANDLES - startupinfo.hStdInput = p2cread - startupinfo.hStdOutput = c2pwrite - startupinfo.hStdError = errwrite + handles = [] + for handle in (p2cread, c2pwrite, errwrite): + if handle is None: + handle = -1 # INVALID_HANDLE_VALUE + else: + startupinfo.dwFlags |= STARTF_USESTDHANDLES + handles.append(handle) + + (startupinfo.hStdInput, + startupinfo.hStdOutput, + startupinfo.hStdError) = handles + if shell: startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE