Search code examples
cwindowsshellmintty

How do I turn echo off under MinTTY?


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?


Solution

  • 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