Skip to content
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

Open
QuentinMillardet mannequin opened this issue May 2, 2018 · 6 comments
Open

All console message are in the error output in bash interpretor #77592

QuentinMillardet mannequin opened this issue May 2, 2018 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-IO type-bug An unexpected behavior, bug, or error

Comments

@QuentinMillardet
Copy link
Mannequin

QuentinMillardet mannequin commented May 2, 2018

BPO 33411
Nosy @stevendaprano, @vadmium, @eryksun, @iritkatriel
Files
  • Capture d'écran du 2018-05-02 16.16.09.png: Screenshot of the problem is clear
  • 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 = None
    closed_at = None
    created_at = <Date 2018-05-02.14:24:09.198>
    labels = ['3.10', 'type-bug', '3.9', 'expert-IO', '3.11']
    title = 'All console message are in the error output in bash interpretor'
    updated_at = <Date 2021-12-07.22:26:41.996>
    user = 'https://bugs.python.org/QuentinMillardet'

    bugs.python.org fields:

    activity = <Date 2021-12-07.22:26:41.996>
    actor = 'eryksun'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['IO']
    creation = <Date 2018-05-02.14:24:09.198>
    creator = 'Quentin Millardet'
    dependencies = []
    files = ['47560']
    hgrepos = []
    issue_num = 33411
    keywords = []
    message_count = 6.0
    messages = ['316073', '316075', '316078', '316199', '407964', '407978']
    nosy_count = 5.0
    nosy_names = ['steven.daprano', 'martin.panter', 'eryksun', 'Quentin Millardet', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33411'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @QuentinMillardet
    Copy link
    Mannequin Author

    QuentinMillardet mannequin commented May 2, 2018

    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)

    @QuentinMillardet QuentinMillardet mannequin added 3.7 (EOL) end of life 3.8 only security fixes topic-IO type-bug An unexpected behavior, bug, or error labels May 2, 2018
    @stevendaprano
    Copy link
    Member

    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.

    @QuentinMillardet
    Copy link
    Mannequin Author

    QuentinMillardet mannequin commented May 2, 2018

    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
    $

    @vadmium
    Copy link
    Member

    vadmium commented May 5, 2018

    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.

    @iritkatriel
    Copy link
    Member

    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.

    @eryksun
    Copy link
    Contributor

    eryksun commented Dec 7, 2021

    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.

    @eryksun eryksun added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life 3.8 only security fixes labels Dec 7, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants