Skip to content

subprocess.Popen doesn't redirect child process' stderr to stdout #126848

@yurivict

Description

@yurivict

Bug report

Bug description:

Testcase:

import time
import subprocess

with open('log', 'w') as log:

    p = subprocess.Popen(['python', 'sp-child.py'],
                         stdout=log,
                         stderr=subprocess.STDOUT)
    time.sleep(10)
    p.communicate()

Additional file sp-child.py:

import sys

print('I am a child!')
print(f' ... in-terminal: stdout={sys.stdout.isatty()} stderr={sys.stderr.isatty()}')

The subprocess.Popen argument requests child's stderr to be redirected to stdout and this doesn't happen.

The child process prints:

I am a child!
 ... in-terminal: stdout=False stderr=False

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions