You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use python-sh to run the following shell equivalent:
$ aws --profile=myprofile ec2 describe-instances >/tmp/instances.json
Enter MFA code:
$
In the example above, the aws command is a Python process that uses getpass.unix_getpass under the hood. When the user enters their password, it sets echo mode off on the TTY so that the password is not visible.
(The "Enter MFA code" is output to stderr and the password is read from stdin but the characters are not echoed.)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py:86: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Enter MFA code:
Indeed, the password is echoed. The line that fails in getpass.py is when TTY options are being set using termios.tcsetattr. The error is:
That is the issue is that sh mis-handles file descriptor 0.
Clearly, you want to do something cleaner and actually close the newly duplicated copy of stdin.
Hi there,
I want to use python-sh to run the following shell equivalent:
In the example above, the
aws
command is a Python process that usesgetpass.unix_getpass
under the hood. When the user enters their password, it sets echo mode off on the TTY so that the password is not visible.(The "Enter MFA code" is output to stderr and the password is read from stdin but the characters are not echoed.)
Here is my attempt to do this using python-sh:
However, this results in:
Indeed, the password is echoed. The line that fails in
getpass.py
is when TTY options are being set usingtermios.tcsetattr
. The error is:I can eliminate this problem by setting
_fg=True
:However, then stdout is not captured.
Is there a way to work around this?
The text was updated successfully, but these errors were encountered: