Correction:
[me@host bin]$ perl -we 'open STDERRIN,"+<&STDERR" or die $!; my $line + = <STDERRIN>; print STDERRIN "YAY!!! $line";' asdfasf YAY!!! asdfasf [me@host bin]$
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):
as well as variations on the theme, like:ls -l /proc/self/fd/
0 = STDIN, 1 = STDOUT, and 2 = STDERR.ls -l /proc/self/fd/ < /dev/null ls -l /proc/self/fd/ | cat ls -l /proc/self/fd/ 2> /dev/null #redrect 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 $!";
In reply to Re: STDIN schizofrenia
by etcshadow
in thread STDIN schizofrenia
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |