With Python 3.11.4, when I use subprocess.run
or subprocess.Popen
to accept "silent" input or "secure input" and then hit ctrl+c, using regular input
afterwards doesn't display text being typed. Here's a reproducible example:
import subprocess
try:
print("hit ctrl+c")
result = subprocess.run("echo $(read -s)", shell=True)
except KeyboardInterrupt:
pass
text = input("Text typed here is not visible: ")
print(text)
Here's my attempt, using Popen, to kill the process (but to no avail):
import subprocess
result = subprocess.Popen("echo $(read -s)", shell=True)
try:
print("hit ctrl+c")
result.wait()
except KeyboardInterrupt:
result.kill()
pass
text = input("Text typed here is not visible: ")
print(text)
How do I go about properly ending the process waiting for silent input so that regular input afterwards is displayed as it's typed?
Edit: I should clarify that I'm building an interface which uses subprocess
to interact with a specific command line tool. That tool prompts the user for input in a "silent" fashion, but I was able to reproduce the problem using echo $(read -s)
in its place.