I have a program that is running under MinTTY (cygwin's shell) and calls to GetConsoleMode/SetConsoleMode fail. _getch echos to the console as well. This is a native win32 app without bindings to the cygwin environment, so any cygwin functions are out. How do I turn off the echo so that I can input a password?

有帮助吗?

解决方案

I essentially emulated the following via popen:

save_state=$(stty -g)

/bin/echo -n "Account: "
read acct
/bin/echo -n "Password: "
stty -echo
read password # this won't echo
stty "$save_state"

echo ""
echo account = $acct and password = $password
Read more at http://www.askdavetaylor.com/how_to_read_password_without_echoing_c.html#Z3FtcTtMHe0gJdES.99 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top