I have a perl Tk gui which is used to run a script i have got all the stdout and stderr from the script to print in the text widget. It also has a help button which inserts a txt file into the text widget. I im trying to get stderr messages from the gui itself to show in the text widget, for example if any of the 'or die' warnings are trigered due to files not being available the 'error' pop up box appears,but if there is an error opening the sub runscripts report.pl, the warning appears in the cmd prompt screen, i want it to appear in the gui popup warning box.
use warnings; use strict; use Tk; use POSIX 'strftime'; use Tk::ErrorDialog; my $DATE = strftime(" report.pl for %d %b %Y " , localtime()); my $title = strftime(" Processing daily Failures for %d %B %Y" , local +time()); my $mw = MainWindow->new; my $filenameA = "c:\\Temp\\perl.txt"; $mw->geometry("720x500"); $mw->title(" report "); my $main_frame = $mw->Frame()->pack(-side => 'top', -fill => 'x'); my $left_frame = $main_frame->Frame(-background => "snow2")->pack(-sid +e => 'left', -fill => 'y'); my $right_frame = $main_frame->Scrolled("Text", -scrollbars => 'se',-b +ackground => "black",-foreground => "green",-height => '44')->pack(-e +xpand => 1, -fill => 'both'); my $failures_button = $left_frame->Button(-text => "$DATE ", -command => [\&runscript])->pack; my $guide = $left_frame->Button(-text => " Clear Screen + ", -command => [\&clear_screen])->pack; my $Close_button = $left_frame->Button(-text => ' Exit + ', -command => [$mw => 'destroy'])->pack; my $Help_button = $left_frame->Button(-text => " Help Guide + ", -command => \&help_file)->pack(-side = +> "bottom"); my $About = $left_frame->Button(-text => ' About + ', -command => \&About_file)->pack(-side => "bottom"); + MainLoop; sub runscript { open (daily_fail, '-|', 'report.pl &') or die "unable to start dail +y_failues.pl"; my $first_line = " please wait......\n $title........\n"; $right_frame->delete("1.0", 'end'); $right_frame->insert( 'end', $first_line ); my $daily_fail_line; while (defined ($daily_fail_line =<daily_fail>) ) { $right_frame->insert( 'end', $daily_fail_line ); $right_frame->update(); $right_frame->see('end'); } } sub clear_screen { $right_frame->delete('1.0','end'); } sub About_file { $right_frame->delete("1.0", 'end'); open (FH, "$filenameA") or die "unable to open c:\\Temp\\perl.txt"; while (<FH>) { $right_frame->insert("end", $_); } close (FH); } sub help_file { system("tk.pl") or die "unable to start c:\\tk.pl"; }

In reply to Perl Tk stderr to show in the Tk gui text widget by john.tm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.