As noted in comments to these questions:
- Weird error after Perl upgrade: Unable to flush stdout
- How to cause "Unable to flush stdout: Broken pipe" in Perl?
perl -e '$SIG{PIPE} = "IGNORE"; sleep(1); print "foo\n";' | echo -n
produces error message Unable to flush stdout: Broken pipe
.
But weirdly
perl -e '$SIG{PIPE} = sub { print STDERR "XXX\n"; }; sleep(1); print "foo\n";' | echo -n
does not produce any message.
Why the second command does not produce a message? How to catch that SIGPIPE event?
The thing I really need is (for an experiment to answer this question) to catch SIGPIPE and when it happens output something to a log file.