Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tieing STDERR to a text widget

0 views
Skip to first unread message

pete

unread,
Mar 8, 2004, 4:58:09 PM3/8/04
to
Hi,

I'd like be to able to redirect warnings from the perl interpreter to a Tk
text widget:

#!/usr/bin/perl -w

use Tk;

$mw = MainWindow->new;
$text= $mw->Text( '-width' => 40, '-height' => 20)->pack;

tie *STDERR, ref $text, $text;

print STDERR "blah";
print $something;

MainLoop;


In the code above, the second print statement generates a warning (since
$something is undefined), but the warning is sent to STDERR on my console,
rather than the tied filehandle.

Any thoughts?

Cheers,

Pete

Robert

unread,
Mar 8, 2004, 5:38:29 PM3/8/04
to
pete wrote:

There is: Tk-Stderr

pete

unread,
Mar 8, 2004, 6:31:15 PM3/8/04
to
Robert wrote:

>> I'd like be to able to redirect warnings from the perl interpreter to a
>> Tk text widget:

[snip]

> There is: Tk-Stderr

Ah, thanks. Looking at the module i've been able to revise my code, and it
works a treat:

#!/usr/bin/perl -w

use Tk;

$mw = MainWindow->new;
$text= $mw->Text( '-width' => 40, '-height' => 20)->pack;

tie *STDERR, ref $text, $text;

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

0 new messages