This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: All console message are in the error output in bash interpretor
Type: behavior Stage:
Components: IO Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Quentin Millardet, eryksun, iritkatriel, martin.panter, steven.daprano
Priority: normal Keywords:

Created on 2018-05-02 14:24 by Quentin Millardet, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
Capture d'écran du 2018-05-02 16.16.09.png Quentin Millardet, 2018-05-02 14:24 Screenshot of the problem is clear
Messages (6)
msg316073 - (view) Author: Quentin Millardet (Quentin Millardet) Date: 2018-05-02 14:24
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)
msg316075 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-05-02 14:45
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.
msg316078 - (view) Author: Quentin Millardet (Quentin Millardet) Date: 2018-05-02 14:55
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
import a
$cat Normal.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
$
msg316199 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-05-05 07:21
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. Issue 1927 currently proposes to make it always go to stderr.
msg407964 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-07 20:49
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) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
msg407978 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-12-07 22:26
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.
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77592
2021-12-07 22:26:42eryksunsetnosy: + eryksun

messages: + msg407978
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
2021-12-07 20:49:03iritkatrielsetnosy: + iritkatriel
messages: + msg407964
2018-05-05 07:21:24martin.pantersetnosy: + martin.panter
messages: + msg316199
2018-05-02 14:55:13Quentin Millardetsetstatus: pending -> open

messages: + msg316078
2018-05-02 14:45:43steven.dapranosetstatus: open -> pending
nosy: + steven.daprano
messages: + msg316075

2018-05-02 14:27:24Quentin Millardetsetstatus: open
2018-05-02 14:26:47Quentin Millardetsetstatus: open -> (no value)
2018-05-02 14:24:09Quentin Millardetcreate