Yet another /dev/fd driver implementation

Yet another /dev/fd driver implementation

Post by Michael Co » Thu, 27 Aug 1992 01:26:14





>   > This is an implementation of the /dev/fd driver. This driver provides
>   > access to a process's file descriptors via the file system name space.
>   > For example, when a process opens /dev/fd/9 the operation performed is
>   > the equivalent of dup(9).
>   > Standard input/output/error (i.e. descriptors 0,1,2) are also visible
>   > as /dev/{stdin,stdout,stderr}.
>   A similar driver has been posted some time ago.  Well, it really
>   *looks* interesting, but what is the advantage for the programmer (or
>   for someone else) to have the file descriptors as files?  
>Just a few examples:
>o Consider your standard brain-dead program fu that will only read from
>  files. With /dev/fd one can hallucinate fu into thinking that it is
>  reading a file when you are feading it stdin.
>    bar | fu /dev/fd/0
>o Suppose that you want to force a program to read from wierd file
>  descriptors without hard-wiring the program.
>    make | groak_cryptic_errors_and_tell_emacs /dev/fd/2
>o Suppose that you want a program to read directly from the output of
>  several programs at once (i.e. non-linear pipes). It can read from
>  /dev/fd/? on any { ? | ? is a valid (open for reading) file descriptor}.

The times I've wished I had /dev/stderr were when I was trying to get my AWK
scripts to send their error messages to stderr.

        print "you goofed" > "/dev/stderr"

(BTW, GAWK'll simulate the /dev/std* and /dev/fd/* mechanisms for you.)

Michael.

 
 
 

Yet another /dev/fd driver implementation

Post by Ravi K Manda » Fri, 28 Aug 1992 04:25:45



Quote:> The times I've wished I had /dev/stderr were when I was trying to get my AWK
> scripts to send their error messages to stderr.
>    print "you goofed" > "/dev/stderr"

BTW, you can send messages to stderr in awk with this:
        print "you goofed" | "/bin/cat 1>&2"

--
*******************************************************************************

*******************************************************************************