I’ve always found the command-line mysql utility to be a bit surprising, because you can do this:
gzcat dumpfile.sql.gz | mysql -u <user> -p <options>
and mysql will prompt you for a password. Now, stdin in mysql is redirected — one would expect it to read the password from the dumpfile. Instead, it somehow bypasses stdin and goes straight for the terminal. ssh does the same kind of thing.
I suspect this is some sort of /dev/tty or /dev/pty magic, but I’d appreciate a proper explanation for this apparent magic 🙂 (and why these programs can do it on any platform, even Windows).
As you surmise, it is using
/dev/tty, which is specified this way:No real “magic” beyond that.
[link]