@@ -807,13 +807,14 @@ def __init__(self, args, bufsize=-1, executable=None,
807807 # quickly terminating child could make our fds unwrappable
808808 # (see #8458).
809809
810- if _mswindows :
811- if p2cwrite != - 1 :
812- p2cwrite = msvcrt .open_osfhandle (p2cwrite .Detach (), 0 )
813- if c2pread != - 1 :
814- c2pread = msvcrt .open_osfhandle (c2pread .Detach (), 0 )
815- if errread != - 1 :
816- errread = msvcrt .open_osfhandle (errread .Detach (), 0 )
810+ # XXX RustPython TODO: have fds for fs functions be actual CRT fds on windows, not handles
811+ # if _mswindows:
812+ # if p2cwrite != -1:
813+ # p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
814+ # if c2pread != -1:
815+ # c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
816+ # if errread != -1:
817+ # errread = msvcrt.open_osfhandle(errread.Detach(), 0)
817818
818819 self .text_mode = encoding or errors or text or universal_newlines
819820
@@ -1154,7 +1155,11 @@ def _get_handles(self, stdin, stdout, stderr):
11541155 else :
11551156 # Assuming file-like object
11561157 p2cread = msvcrt .get_osfhandle (stdin .fileno ())
1158+ # XXX RUSTPYTHON TODO: figure out why closing these old, non-inheritable
1159+ # pipe handles is necessary for us, but not CPython
1160+ old = p2cread
11571161 p2cread = self ._make_inheritable (p2cread )
1162+ if stdin == PIPE : _winapi .CloseHandle (old )
11581163
11591164 if stdout is None :
11601165 c2pwrite = _winapi .GetStdHandle (_winapi .STD_OUTPUT_HANDLE )
@@ -1172,7 +1177,11 @@ def _get_handles(self, stdin, stdout, stderr):
11721177 else :
11731178 # Assuming file-like object
11741179 c2pwrite = msvcrt .get_osfhandle (stdout .fileno ())
1180+ # XXX RUSTPYTHON TODO: figure out why closing these old, non-inheritable
1181+ # pipe handles is necessary for us, but not CPython
1182+ old = c2pwrite
11751183 c2pwrite = self ._make_inheritable (c2pwrite )
1184+ if stdout == PIPE : _winapi .CloseHandle (old )
11761185
11771186 if stderr is None :
11781187 errwrite = _winapi .GetStdHandle (_winapi .STD_ERROR_HANDLE )
@@ -1192,7 +1201,11 @@ def _get_handles(self, stdin, stdout, stderr):
11921201 else :
11931202 # Assuming file-like object
11941203 errwrite = msvcrt .get_osfhandle (stderr .fileno ())
1204+ # XXX RUSTPYTHON TODO: figure out why closing these old, non-inheritable
1205+ # pipe handles is necessary for us, but not CPython
1206+ old = errwrite
11951207 errwrite = self ._make_inheritable (errwrite )
1208+ if stderr == PIPE : _winapi .CloseHandle (old )
11961209
11971210 return (p2cread , p2cwrite ,
11981211 c2pread , c2pwrite ,
0 commit comments