Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b369358

Browse files
author
Victor Stinner
committed
Issue #8780: Fix a regression introduced by r78946 in subprocess on Windows
Ensure that stdout / stderr is inherited from the parent if stdout=PIPE / stderr=PIPE is not used.
1 parent f978fac commit b369358

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
843843
# Process startup details
844844
if startupinfo is None:
845845
startupinfo = STARTUPINFO()
846-
if None not in (p2cread, c2pwrite, errwrite):
846+
if -1 not in (p2cread, c2pwrite, errwrite):
847847
startupinfo.dwFlags |= _subprocess.STARTF_USESTDHANDLES
848848
startupinfo.hStdInput = p2cread
849849
startupinfo.hStdOutput = c2pwrite

Lib/test/test_subprocess.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,17 @@ def test_leaking_fds_on_error(self):
535535
if c.exception.errno != 2: # ignore "no such file"
536536
raise c.exception
537537

538+
def test_issue8780(self):
539+
# Ensure that stdout is inherited from the parent
540+
# if stdout=PIPE is not used
541+
code = ';'.join((
542+
'import subprocess, sys',
543+
'retcode = subprocess.call('
544+
"[sys.executable, '-c', 'print(\"Hello World!\")'])",
545+
'assert retcode == 0'))
546+
output = subprocess.check_output([sys.executable, '-c', code])
547+
self.assert_(output.startswith(b'Hello World!'), ascii(output))
548+
538549

539550
# context manager
540551
class _SuppressCoreFiles(object):

0 commit comments

Comments
 (0)