Commit 95c7cce9 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Fix interactive mode to use stdout or stderr depending on what is a tty

To match python behaviour:

    $ python >/dev/null
    Python 2.7.18 (default, Apr 20 2020, 20:30:41)
    [GCC 9.3.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+1			# NOTE the prompt (printed to stderr)

    $ python 2>/dev/null
    >>> 1+1			# NOTE the prompt (printed to stdout)

Tests pending.

/reviewed-by @jerome
/reviewed-on nexedi/pygolang!15
parent 22fb559a
......@@ -273,11 +273,16 @@ def _interact():
console = code.InteractiveConsole()
def _(prompt):
# python behaviour: don't print '>>>' if stdin is not a tty
# python behaviour:
# - use stdout for prompt by default;
# - use stderr for prompt if any of stdin/stderr is not a tty
# (builtin raw_input always prints prompt)
if not sys.stdin.isatty():
prompt=''
return raw_input(prompt)
promptio = sys.stdout
if (not sys.stdin.isatty()) or (not sys.stdout.isatty()):
promptio = sys.stderr
promptio.write(prompt)
promptio.flush()
return raw_input('')
console.raw_input = _
console.interact()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment