Pregunta

Me gustaría escribir un programa que lee la entrada del usuario sólo desde TTY, en lugar de tubos de stdin redirigidas, como passwd y ssh do. ¿Hay algún método?

Muchas gracias

¿Fue útil?

Solución

You should try opening /dev/tty directly. That's the only way I know for sure that you can bypass the stdin redirection.

/dev/tty is usually a symbolic link to your actual tty device, which may be /dev/console or /dev/tty24 or pretty much anything you want, depending on the weird and wonderful way your system may be set up. The tty command should be able to tell you which one it is (as will listing the symbolic link itself with ls -al /dev/tty).

But as long as you open dev/tty for input, it should get the input from your terminal rather than the standard input stream, which may have been redirected.

Otros consejos

You can try isatty(man 3 isatty) in conjunction with fileno():

   #include <unistd.h>

   int isatty(int fd);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top