I’d like to write a program which reads user input only from tty, instead of redirected stdin pipes, like passwd and ssh do. Is there any approach?
Many thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should try opening
/dev/ttydirectly. That’s the only way I know for sure that you can bypass thestdinredirection./dev/ttyis usually a symbolic link to your actual tty device, which may be/dev/consoleor/dev/tty24or pretty much anything you want, depending on the weird and wonderful way your system may be set up. Thettycommand should be able to tell you which one it is (as will listing the symbolic link itself withls -al /dev/tty).But as long as you open
dev/ttyfor input, it should get the input from your terminal rather than the standard input stream, which may have been redirected.