What is -t used in this Perl code

I read in perldoc that the -t file operator is used to determine if a file descriptor is open in tty or not. Then I read what tty is, and from what I understand, is this an old term for a terminal?

My main question, however, is what is this code used for:

if(-t STDERR) {
    die "some warning/error message here"
}

I think I don’t quite understand what this means that “the file descriptor opens on tty”. Does this mean that the specific output of this file descriptor appears on tty - or on the terminal? Can tty refer to something other than a terminal?

+4
source share
2 answers

This code wants to claim that a standard error is redirected to a file. So run

perl the_script.pl

die,

perl the_script.pl 2> error.log

.

+6

unix. ttys ,

" STDERR ,..."

. , /dev/tty*. , . , Expect IO:: Pty .

STDERR , . -t .

script 2>foo        # Plain file
script 2>&1 | cat   # Pipe
+6

All Articles