Leonard Wauters - 2012-03-30


Just a little contribution after some time spent on this specific problem.

I wanted to see messages issued by warn() on the debug console inside Eclipse, but as far as I could see, with an initial set-up, such messages do not show up. Whereas in a normal execution, warn() messages are correctly displayed to the console.

The reason is because your script's STDERR gets redirected to the debugger's STDOUT from EPIC's point of view or something like that. That's what I could see doing strace during the scrip'ts debug : warn() do not write to FH 2, but FH 4. If someone has a more clear explanation, please do so.

The workaround is the following : Use the following code at teh beginning of your script :

sub WARN_handler {
    print STDERR @_ ;
$SIG{'__WARN__'} = 'WARN_handler';

How does it works ? If there is a handler for __WARN__ signal, warn() sub will call the subsequent handler instead of writing to STDERR directly. Very useful to catch all warn() messages and redirect them to whatever you want.
Here, we explicitly redirect them to STDERR. This way, you will see warn() messages from your scripts on the Epic console.

BTW this is very useful to debug you code, as most Perl libs and built-in subs use warn() to tell you that something is wrong.