Quote:
|
Originally Posted by fdarkangel
i too have a question on the topic.
how do i read from keyboard if stdin is actually stdout of another program. an example is less/more: keyboard input still works when they're piped.
|
This is more of a separate question. You probably should have started a new thread.
If you type "tty", you will see the name of your controlling terminal. If it is, say, /dev/pty/j2, then you could simply open that file to gain access to the keyboard. But it is a lot of work to get the name of your particular terminal, so there is a second way. In the unix environment, a process with a controlling terminal can open the special file /dev/tty and get their own controlling terminal. This won't work if there is no crontrolling terminal such as with a cron job. Even though there is only one file on the system called /dev/tty, each user that opens it will get his or her own keyboard.
However, this may not be a great move to make. Suppose that I have a complicated pipeline of 4 processes. If they all do this at the same time it will be pretty hopeless to get it all straight. And look at all the threads we get where folks need to script the su command and must "expect" to do it. Users tend to dislike programs that do this.