Last active
June 13, 2023 18:21
-
-
Save mtik00/96f614b09344de5831cd0ebfcdc6dfb4 to your computer and use it in GitHub Desktop.
read password from stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can check to see if someone ran your script with `echo -n test | myscript.py`. | |
# In that case, there's no tty attached. If there _is_ an attached tty, then you | |
# can just prompt the user like normal. | |
import sys | |
def read_secret_key(): | |
if sys.stdin.isatty(): | |
return getpass("Enter the secret key: ") | |
else: | |
return sys.stdin.readline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment