I would like Perl to write to STDERR only if STDOUT is not the same. For example, if both STDOUT and STDERR redirected output to a terminal, then I do not want to print STDERR.
Consider the following example (outerr.pl):
#!/usr/bin/perl use strict; use warnings; print STDOUT "Hello standard output!\n"; print STDERR "Hello standard error\n" if ($someMagicalFlag); exit 0
Now consider this (which I would like to achieve):
bash $ outerr.pl Hello standard output!
However, if I redirect to a file, I would like to get:
bash $ outerr.pl > /dev/null Hello standard error
and similarly:
bash $ outerr.pl 2> /dev/null Hello standard output!
If I redirect both / err options to the same file, then only the output should be displayed:
bash $ outerr.pl > foo.txt 2>&1 bash $ cat foo.txt Hello standard output!
So, is there a way to evaluate / determine whether OUT and ERR are and point to the same βthingβ (handle?)?
source share