For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2004 > How to redirect perl and Tk errors to a widget instead of shell?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to redirect perl and Tk errors to a widget instead of shell?
Johnny Google

2004-11-09, 3:57 pm

I want to remove my command shell from my perl tk app yet i would like
to still be able to see perl and Tk errors when they happen.

I currently have a ROText widget for my application status - and would
like this to be the place where any error from the .pl or specific to
Tk to be inserted.

Is there a way to do this?

Thanks,

John

thundergnat

2004-11-09, 8:56 pm

Johnny Google wrote:
> I want to remove my command shell from my perl tk app yet i would like
> to still be able to see perl and Tk errors when they happen.
>
> I currently have a ROText widget for my application status - and would
> like this to be the place where any error from the .pl or specific to
> Tk to be inserted.
>
> Is there a way to do this?
>
> Thanks,
>
> John
>



see this article:
http://groups.google.com/groups?hl=...3%40newsfe1-win
zentara

2004-11-10, 8:56 pm

On 9 Nov 2004 12:18:24 -0800, "Johnny Google" <john_pataki@yahoo.com>
wrote:

>I want to remove my command shell from my perl tk app yet i would like
>to still be able to see perl and Tk errors when they happen.
>
>I currently have a ROText widget for my application status - and would
>like this to be the place where any error from the .pl or specific to
>Tk to be inserted.
>
>Is there a way to do this?


Just put

require Tk::ErrorDialog;

at the top of your Tk script...works for me.
That will pop up an error message in a separate toplevel.

To redirect it to your ROText widget, you probably want to
close STDERR, then reopen it to a filehandle, then use fileevent
to read it and put it in your ROText.

Here are a couple of other ideas for you.
#####################################
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Stderr;

my $mw = MainWindow->new->InitStderr;
print STDERR 'stuff'; ## goes to standard error window
warn '!'; ## likewise
MainLoop;
####################################

or

########################################
#
#!/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 @_ };

print STDERR "blah blah blah";

$something = 'hoo hah';
print "$something\n";

MainLoop;
########################################
#

















--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com