consequences of stderr redirection

Rick Schubert rns at se-sd.SanDiego.NCR.COM
Sat Oct 20 09:10:33 AEST 1990


In <4066 at se-sd.SanDiego.NCR.COM> bhoule at se-sd.SanDiego.NCR.COM (Bill Houle) writes:

>Just curious: why does redirection of stderr give 'vi' and 'less'
>the fits?  What is happening internal to those programs when stderr 
>is not /dev/tty?  Also, 'pg' seems to work fine but more displays 
>the first page and quits....

It appears that these programs use stderr (file descriptor 2) for their
`ioctl' calls to put the terminal into whatever mode it needs to be in
to do single character input (probably either "raw" or "cbreak" mode).
`ioctl' needs a file descriptor to act on, even though it is a global and
process independent change to the terminal.  If stderr is redirected, the
`ioctl' is done (or fails) on whatever file stderr is redirected to; however,
`vi' and `less' assume that stdin (file descriptor 0) was affected.
There might be some reason for doing the `ioctl' on fd 2 rather than fd 0,
but I don't know what it is (maybe because stdin is redirected more often
than stderr).

-- Rick Schubert (rns at se-sd.sandiego.NCR.COM)

P.S. Normally I would have waited to respond to this article since 
there are usually many responses to questions like this.  I'm only
answering now since Bill is on the same machine I am, so my answer
will get to him quicker and may get to you at the same time that
his question did.  If I gave a good answer, no need for anyone else
to post an answer.  If I was wrong, I'm sure I'll hear about it.



More information about the Comp.unix.questions mailing list