in reply to Re^8: Tk gui bug
in thread Tk gui bug

You need to open up your external programs with IPC::Open3 ( possibly a 2>&1 redirect in a piped open), but IPC::Open3 is you general purpose solution. Here is a basic example, you setup a fileevent on the inputs:
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use Tk; my $mw = new MainWindow; $mw->geometry("600x400"); $mw->Button(-text => "See STDERR", -command => \&do_Toplevel)->pack(); my $tout = $mw->Scrolled( 'Text', -foreground => 'white', -background => 'black', -width => 80, -height => 20, )->pack; my $top = $mw->Toplevel(); $top->withdraw; my $terr = $top->Scrolled( 'Text', -foreground => 'hotpink', -background => 'black', -width => 80, -height => 20, )->pack; my $pid = open3( 0, \*OUT, \*ERR, "$0-sender" ); #the 0 is for ignoring \*IN (STDIN) $mw->fileevent( \*OUT, 'readable', \&write_out ); $mw->fileevent( \*ERR, 'readable', \&write_err ); MainLoop; ##################################################### sub do_Toplevel { if (! Exists($top)) { $top = $mw->Toplevel( ); $top->title("T-ERR"); $top->Button(-text => "Close", -command => sub { $top->withdraw })->pack; } else { $top->deiconify( ); $top->raise( ); } } ############################### sub write_out { my $str = <OUT>; $tout->insert( "1.0", $str ); $tout->see("1.0"); } ############################ sub write_err { my $str = <ERR>; $terr->insert( "1.0", $str ); $terr->see("1.0"); } ########################################### __END__
and the simple sender to play with
#!/usr/bin/perl use warnings; use strict; $| = 1; my $count = 0; while(1){ $count++; print "$count\n"; warn "\tuh oh warning $count\n"; sleep 1; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^10: Tk gui bug
by honyok (Sexton) on Feb 06, 2009 at 06:31 UTC
    I can't get your first bit of code to run properly. I only get a graphic if I comment out these lines:
    $mw->fileevent( \*OUT, 'readable', \&write_out ); $mw->fileevent( \*ERR, 'readable', \&write_err );
    Otherwise no errors or warnings - just stalls at the command line.
        I'm using ssh through cygwin to Linux machines. I'm also trying VNC which at least pops up a blank window.
        AAaaaaaaaaaaargggggghhhhhh!!!!!!!! Forget external programs, what about piping STDOUT and STDERR from a shell script initiated from the GUI. HELP!