-
-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
All console message are in the error output in bash interpretor #77592
Comments
The probleme is all display (normal and error message), in bash, are send to the screen by the error output. So it's impossible when someone make a bash script to get the error back in a log file for exemple, or just to display only the error on a screen. Problem test on Ubuntu 18.04 and Elementary loki (an Ubuntu 16.04 variant) |
Hello Quentin, and welcome. Please don't post screen shots of text. We don't edit our code with Photoshop, and using a screenshot makes it difficult to copy your code for testing, to verify the bug report, and prevents the blind and visually impaired from taking part on the discussion. Please copy and paste the code demonstrating the error as text, the output you received, and state the output you expected. |
In a bash terminal, obtained result: $python > Normal.txt 2> Error.txt
import a
$cat Normal.txt
$cat Error.txt
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named a
>>>
$ That i was expected : $python > Normal.txt 2> Error.txt Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> $cat Error.txt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named a
$ |
The exception message and stack trace is documented to go to stderr: <https://docs.python.org/2/library/sys.html#sys.excepthook\>. Whether the prompt “>>>” goes to stderr or stdout depends on quirks of the environment. bpo-1927 currently proposes to make it always go to stderr. |
I think the question here is why this went to stderr rather than stdout: Python 2.7.12 (default, Dec 4 2017, 14:50:18) |
PyOS_Readline() calls PyOS_StdioReadline() if sys_stdin or sys_stdout isn't a tty file. This function always writes the prompt to stderr, as follows: if (prompt) {
fprintf(stderr, "%s", prompt);
}
fflush(stderr); Maybe this matched the behavior of the readline module and/or GNU Readline in the past. It's definitely *not* the case in Linux with Python 2.x or 3.x with readline linked to "libreadline.so.8". In this case, the prompt gets written to stdout. For example: $ python -q 2>err.txt
>>> import a
>>> $
$ cat err.txt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'a' In Windows, OTOH, the readline module isn't available in the standard library, in which case PyOS_StdioReadline() is called. For the io._WindowsConsoleIO update in 3.6, this function was modified to use ReadConsoleW() and WriteConsoleW() instead of my_fgets(). But I think modifying PyOS_StdioReadline() was a mistake. The changes should have been implemented as a new hook for PyOS_ReadlineFunctionPointer. This should have used stdout for the prompt instead of stderr, normalizing the behavior with interactive readline on other platforms. Whether or not stderr is redirected to a file or pipe should make no difference on the behavior. |
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: