Skip to content

termios.tcgetattr changes settings rather than just returning them #9

Description

@sebbASF

old = termios.tcgetattr(fd) # a copy to save

This is using Python 3.13.1+ on a-shell Mini (iPad Mini)

Whilst trying to investigate why getpass.getpass() does not recognise the Enter or ^d key as input terminator, I discovered that this appears to be caused by termios.tcgetattr(fd)

For a simple demo, try the following:

import sys
import termios
print(repr(sys.stdin.readline())) # this behaves as expected; Enter terminates input, as do ^D (EOF) and ^J
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
print(repr(sys.stdin.readline())) # this does not behave as expected; only ^J terminates input; Enter is converted into CR

This means that using getpass.getpass() does not return sys.stdin to its original state.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions