in reply to Perl/Tk App and Interprocess Communication
The following demonstrates a Tk app that updates the screen in response to the output from another Perl process in real time:
#!perl -slw use strict; use threads; use threads::shared; ## A shared var to communicate progress between work thread and TK my $progress : shared = 0; sub work{ open PROC, 'perl -le"$|=1; print and select(undef,undef,undef,0.1) for 1 .. + 1000" |' or die $!; while( <PROC> ) { lock $progress; $progress = $_; } close PROC; } threads->new( \&work )->detach; require Tk::ProgressBar; my $mw = MainWindow->new; my $pb = $mw->ProgressBar()->pack(); my $repeat; $repeat = $mw->repeat( 100 => sub { # print $progress; $repeat->cancel if $progress == 100; $pb->value( $progress ) } ); $mw->MainLoop;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl/Tk App and Interprocess Communication
by beretboy (Chaplain) on Jun 30, 2005 at 15:03 UTC | |
by BrowserUk (Patriarch) on Jun 30, 2005 at 18:25 UTC |