You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarify documentation for redirected stdout/stderr when using subprocess in Linux #88324
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-05-17.19:46:00.282>labels= ['easy', 'type-bug', '3.9', '3.10', '3.11', 'docs']
title='Clarify documentation for redirected stdout/stderr when using subprocess in Linux'updated_at=<Date2022-04-05.09:31:13.894>user='https://github.com/tanty'
"
Note that the global side effect on sys.stdout means that this context manager is not suitable for use in library code and most threaded applications. It also has no effect on the output of subprocesses.
"
5. The stdout and stderr for the subprocess-ed command is not redirected, as stated in the contextlib documentation.
It took me a while to realize that redirecting stdout and stderr didn't have an effect in the child subprocess.
It would be great if this could be improved so the subproccess-ed command also inherits the redirection. At the very least, this issue with the redirection should be added as a notice in the subprocess documentation.
The attached test.py script shows this behavior. The code is very simple and self-explanatory. You can run with:
Hmm, I'm not quite following - when you say that the subproccess-ed command should also inherit the redirection, which subprocess command are you referring to, and nested or unnested? I gave it a ran and everything seems to run how I'd expected it, so maybe put another way, what's the expected output from the files and stdout/stderr?
Activity
tanty commentedon May 17, 2021
https://docs.python.org/3/library/subprocess.html#frequently-used-arguments
"
With the default settings of None, no redirection will occur; the childâs file handles will be inherited from the parent.
"
https://docs.python.org/3/library/contextlib.html?highlight=contextlib#contextlib.redirect_stdout
"
Note that the global side effect on sys.stdout means that this context manager is not suitable for use in library code and most threaded applications. It also has no effect on the output of subprocesses.
"
5. The stdout and stderr for the subprocess-ed command is not redirected, as stated in the contextlib documentation.
It took me a while to realize that redirecting stdout and stderr didn't have an effect in the child subprocess.
It would be great if this could be improved so the subproccess-ed command also inherits the redirection. At the very least, this issue with the redirection should be added as a notice in the subprocess documentation.
The attached test.py script shows this behavior. The code is very simple and self-explanatory. You can run with:
# test.py
or
# test.py -n
Somehow, related to: https://bugs.python.org/issue1227748
1 remaining item
slateny commentedon Apr 5, 2022
Hmm, I'm not quite following - when you say that the subproccess-ed command should also inherit the redirection, which subprocess command are you referring to, and nested or unnested? I gave it a ran and everything seems to run how I'd expected it, so maybe put another way, what's the expected output from the files and stdout/stderr?
gh-88324: Clarify documentation for redirected stdout/stderr when usiâĶ