sender_program script ( like your C++ program)
#!/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; }
and the Tk reader script
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use Tk; use Tk::ProgressBar; my $mw = new MainWindow; $mw->geometry("600x400"); my $tframe = $mw->Frame()->pack(); my $count = 0; my $l1 = $tframe->Label(-text => '%', -bg => 'black', -fg => 'green', )->pack(-side => 'left'); my $l2 = $tframe->Label( -text => $count, # -text option better here, than textvariable which # may cause unicode display problem #-textvariable => \$count, #may cause unicode display problem over a socket -bg => 'black', -fg => 'green', -width => 3, )->pack(-side => 'left'); my $p = $tframe->ProgressBar( -troughcolor => 'black', -fg => 'lightgreen', -blocks => 1, -width => 20, -length => 200, -from => 0, -to => 100, -variable => \$count, )->pack(-side =>'right'); my $tout = $mw->Scrolled( 'Text', -foreground => 'white', -background => 'black', -width => 80, -height => 20, )->pack; $tout->tagConfigure( 'red', -foreground => 'red' ); my $pid = open3( 0, \*OUT, \*ERR, "sender_program" ); #the 0 is for ignoring \*IN (STDIN) $mw->fileevent( \*OUT, 'readable', \&write_out ); $mw->fileevent( \*ERR, 'readable', \&write_err ); MainLoop; ############################################### sub write_out { $count = <OUT>; chomp $count; # eval $count; #prevents raw unicode, you may not need it # print "$count\n"; $l2->configure( '-text' => $count); # works better than textvaria +ble $tout->insert( "end", "$count\n" ); $tout->see("end"); } ############################################ sub write_err { my $str = <ERR>; $tout->insert( "end", "\t$str", 'red' ); $tout->see("end"); } __END__
In reply to Re: Perl/Tk C++ Interaction
by zentara
in thread Perl/Tk C++ Interaction
by dmarg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |