Gambling1uk has asked for the wisdom of the Perl Monks concerning the following question:
As you'll see by the commented out line I have been trying to use the filevent command to pipe things and have had a little bit of success but not really too much. If you can help with this it is going to solve a long standing problem in my understanding of how perl and tk talk.#!/usr/bin/perl -w # use strict; # use Encode::Unicode; use Tk; # open(H, "tail -f -n 25 $ARGV[0]|") or die "Nope: $!"; # open(STDOUT, "+> |") or die "Nope: $!"; # open STDOUT, '+<', \&test or die "Can't open STDOUT: $!"; $mw=MainWindow->new(); # create main window, and stretch it to fill sc +reen minus a bit $mw->title("GRM Consulting Ltd. - GENESIS Optimisation Coupling Tool v +1.0"); $mw->geometry("800x600+100+100"); my $t = $mw->Text(-width => 80, -height => 25, -wrap => 'none'); $t->pack(-expand => 1); # $mw->fileevent(\*STDOUT, 'readable', [\&fill_text_widget, $t]); $mw->update; test(); MainLoop; sub fill_text_widget { my($widget) = @_; my($stat, $data); $stat = sysread STDOUT, $data, 4096; die "sysread error: $!" unless defined $stat; $widget->insert('end', $data); $widget->yview('end'); } ## Test routine to simulate my main program execution sub test { for ($i=0; $i<3; $i++ ) { print "testline $i\n"; sleep 1; } $command="dir"; system("$command"); for ($i=0; $i<3; $i++ ) { print "testline1 $i\n"; sleep 1; } die; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Executing pipe STDOUT from a subroutine to Widget
by Joost (Canon) on May 15, 2008 at 11:10 UTC | |
by Anonymous Monk on May 15, 2008 at 12:28 UTC | |
|
Re: Executing pipe STDOUT from a subroutine to Widget
by zentara (Cardinal) on May 15, 2008 at 13:58 UTC |