NaSe77 has asked for the wisdom of the Perl Monks concerning the following question:

Felow Monks,

I search a way to redirect the STDERR of my programm into a nice Tk Window . I'm sure there is a easy way to do it, but if i tried it with using a fileevent

$main->fileevent(\*STDERR,'readable',[\&tackle_err]); sub tackle_err{ $_ = <STDERR>; my $error_window = $main->Toplevel(); $error_window -> Label ( -text => $_ )->pack; $error_window -> Button ( -text => "OK", -command => sub {$error_window->destroy} )->pack; }
i got as error
Use of uninitialized value in <HANDLE> at /usr/lib/perl5/site_perl/5.6 +.1/i386-linux/Tk/Event/IO.pm line 46.
thanks for your wisdom ...

NaSe

Replies are listed 'Best First'.
Re: redirecting STDERR
by ozone (Friar) on May 16, 2002 at 10:06 UTC
    Your sub should start more like this:
    sub tackle_err{ my $file_handle = shift; $_ = <$file_handle>;
    You weren't reading from the filehandle you passed in. Not sure why you got an undef back from reading the handle directly though. <thumbsuck>Might be TK opening the filehandle directly, so you no longer have direct access ... </thumbsuck>
      it works now thanx (i use now Tk::ErrorDialog and sub tackle_err with the errormessage as argument):
      use Tk::ErrorDialog; sub tackle_err{ my $label_text = shift; my $error_window = $main->Toplevel( -title => "Error!!" ); $error_window -> Label ( -text => $label_text )->pack( -side=>"top", -expand=>1, -padx=>100, -anchor=>'n' ); $error_window -> Button ( -text => "OK", -command => sub {$error_window->destro +y} )->pack; }

      NaSe

Re: redirecting STDERR
by particle (Vicar) on May 16, 2002 at 10:58 UTC
    ozone gave a good piece of advice. i'd like to add that there's no reason to pass \*STDERR when *STDERR will do. typeglobs like being passed around as they are, and it's very efficient to boot.

    ~Particle *accelerates*

      remark :

      it doesn't work if i don't use a ref there:

      Not a GLOB reference at /usr/lib/perl5/site_perl/5.6.1/i386-linux/Tk/E +vent/IO.pm line 107.

      NaSe

        hrumph. silly me, i should have read the doc for that.

        ~Particle *accelerates*