[comp.unix.questions] /dev/stdin

newcomb@cory.Berkeley.EDU (Tom Newcomb) (06/26/88)

After reading all the flap about /dev/stdin (and its omission from BSD UNIX), I
thought a while about the problem.  First, is /dev/stdin supposed to be just a
link of sorts to one's TTY input?  I can't think of anything else it should
reference, except perhaps fd0 in a shell script (and here, admittedly, my
case is worthless).  If you want to do something like:

egrep 'Lo\!  The Hounds of Hell eat Puppy Chow\!' `cat files /dev/stdin`'

then would not /dev/stdin be referring to TTY input?  I should think that it
would always be used on command lines where stdin is not being redirected; I
don't know of too many programs that let you get away with something like this:

cat /dev/stdin < whangdoodle	; Send stdin and 'whangdoodle' to stdout

(Would /dev/stdin in this case be referring to 'whangdoodle', since it's now
standard input...?)

So, if all you want is the TTY input, why not use /dev/tty?  It's worked
beautifully in all the cases I've tried.  So, what am I missing?  Can anybody
come up with a case where /dev/stdin would NOT be /dev/tty, besides shell
scripts? (I already know this won't work for scripts run from a shell whose
input has been redirected.)  In a C program, also, you can just do an
fdopen(3) on descriptor 0 (and that ALWAYS works).

PLEASE send comments through E-MAIL!!!!  I promise I'll summarize in a week or
so.  Many thanks.


Tom Newcomb			| WEST, v.  West is what wabbits do when they
newcomb@cory.Berkeley.EDU	| 	get tired of wunning awound.

denbeste@bgsuvax.UUCP (William C. DenBesten) (06/27/88)

From article <4096@pasteur.Berkeley.Edu>, by newcomb@cory.Berkeley.EDU (Tom Newcomb):

> So, if all you want is the TTY input, why not use /dev/tty?  It's worked
> beautifully in all the cases I've tried.  So, what am I missing?  Can anybody
> come up with a case where /dev/stdin would NOT be /dev/tty, besides shell
> scripts?

sure.

      ls -1 | sort -r -

The dash at the end indicates to sort that it should do a fdopen(0).
The problem is that this causes ugly special case code within sort.  If I
instead said:

       ls -1 | sort -r /dev/stdin

the OS would deal with the fact that I want stdin.  This would clean
up code, since the file opening code can be located in just one place.
In addition, you could then pipe input into programs that were not
designed to use standard input.

-- 
 William C. DenBesten
 denbeste@bgsu.edu