| Next | System Programming in Perl | 20 | 
In Perl, the code might look something like this:
(If you love C)
        @statinfo = stat STDOUT;
        if (    $statinfo[2] & 0060000 == 0020000
            && ($statinfo[6] & 0xff) == 5) { say "Terminal" }
        else { say "Not a terminal" }
Or more likely, for portability reasons, you'd use isatty:
        use POSIX 'isatty';
        if (isatty(STDOUT)) { say "Terminal" } 
        else { say "Not a terminal" }
Or even more likely, you'd use Perl's built-in -t operator
        if (-t STDOUT) { say "Terminal" } 
        else { say "Not a terminal" }
Internally, -t just uses isatty
isatty itself is highly system-dependent
On my GNU/Linux system it uses ioctl
| Next | ![]()  | 
    20 |