New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subprocess.Popen(stderr=STDOUT) fails to redirect subprocess stderr to stdout #66470
Comments
The following command should not produce any output but it does: $ ./python >/dev/null -c 'import subprocess as S, sys; S.call([sys.executable, "-c", "import sys; print(42, file=sys.stderr)"], stderr=S.STDOUT)' Its stdout is redirected to /dev/null. It starts a subprocess with its [1] http://stackoverflow.com/questions/11495783/redirect-subprocess-stderr-to-stdout I've uploaded a patch that fixes the issue on POSIX. Please, run the provided test (in the patch), to see whether the code No documentation changes are required. Please, review. |
Okay, dumb question: Is there a reason the Windows code explicitly initializes c2pwrite in the "stdout not passed" case, while the Linux code leaves it as -1? Windows doesn't look like it would have the problem (because c2pwrite is always set to a non-default value), and it seems like the fix for Linux could just mimic the Windows approach; the code that sets errwrite wouldn't change, but instead of a "pass", when stdout is None, we'd explicitly set it to os.STDOUT_FILENO, and the stderr=subprocess.STDOUT (stdout unset) case would work automatically, and the code would be more similar. Haven't explored the negative consequences of that change, if any. |
Josh, on Windows, if at least one standard stream is replaced; all three My patch leads to dup2(fileno(stdout), STDERR_FILENO) when stdout is sys.__stdout__ is used so that the call fails sooner without fork() if |
Updated the patch to address vadmium's review comments. |
I think this patch is pretty good. I will try to commit it in the next few days. |
New changeset 642933771fa5 by Martin Panter in branch '3.5': New changeset 5979e7aadd59 by Martin Panter in branch 'default': New changeset 5f46ecaf8c6e by Martin Panter in branch '2.7': |
Thanks for the patch Akira. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: