如何在MinTTY下关闭回声?

时间:2012-11-27 00:37:41

标签: c windows shell mintty

我有一个在MinTTY(cygwin的shell)下运行的程序,并且对GetConsoleMode / SetConsoleMode的调用失败。 _getch回到控制台。这是一个原生的win32应用程序,没有绑定到cygwin环境,所以任何cygwin功能都没有。如何关闭回声以便输入密码?

1 个答案:

答案 0 :(得分:1)

我基本上通过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