in reply to STDIN schizofrenia

You can read from STDERR. It's just as easy as <STDERR>.

Correction:

If you are not redirecting, then STDIN, STDOUT and STDERR are really all references to the same thing, your terminal. You can see this by running (at least on linux):

ls -l /proc/self/fd/
as well as variations on the theme, like:
ls -l /proc/self/fd/ < /dev/null ls -l /proc/self/fd/ | cat ls -l /proc/self/fd/ 2> /dev/null #redrect STDERR
0 = STDIN, 1 = STDOUT, and 2 = STDERR.

If you want to be clever, then you can try to detect which of STDIN, STDOUT and STDERR are actually terminals, by using the -t operator. Also, you could just reach around the standard IO channels and open a direct shot to the controlling tty of the process like:

open TTY, ">/dev/tty" or die "Couldn't open /dev/tty $!";

------------
:Wq
Not an editor command: Wq

Replies are listed 'Best First'.
Re: STDIN schizofrenia
by Abigail-II (Bishop) on Oct 13, 2003 at 09:42 UTC
    You can read from STDERR. It's just as easy as <STDERR>.
    Really?
    $ perl -wle 'print while <STDERR>' Filehandle STDERR opened only for output at -e line 1. $

    How do you plan to read from STDERR, and how do you tell your terminal that what you type should be connected the the STDERR of the foreground job?

    Abigail

      ACK! My bad for posting untested code. You have to dupe STDERR to pull this off:
      open STDERRIN,"<&STDERR" or die "Could not dupe STDERR for input: $!\n +"; my $line = <STDERRIN>;
      While STDERR is a file-descriptor to your terminal (if you haven't redirected stdout), it is only an outbound channel... so you need to open an inbound channel to the same device if you want to read from it.

      ------------
      :Wq
      Not an editor command: Wq
        $ perl -wle 'open STDERRIN,"<&STDERR" or die $!; my $line = <STDERRIN> +' Filehandle STDERRIN opened only for output at -e line 1. $

        Abigail