in reply to (Solved) Perl Tk: STDOUT and STDERR to ROText

The while loop is blocking the eventloop. You have to use a thread or IPC of somesort to fork or thread your code. An alternative, would be to avoid the while(1) loop and sleep with a repeater. See the simple example below.

If you wanted a random timer interval, you would have to run each timer onetime only, spawning another timer as it's last action.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); $mw->fontCreate('big', -size => 16 ); my $tx = $mw->Text(-bg=> 'white', -font=>'big', -width => 25)->pack(); tie *STDOUT, 'Tk::Text', $tx; $mw->repeat(1000, \&tick); MainLoop; my $count; sub tick { ++$count; print "$count\n"; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Perl Tk: STDOUT and STDERR to ROText
by Karkadan (Initiate) on Feb 15, 2012 at 20:40 UTC

    Hi Zentara,

    Thanks for your suggestion. Using timer functions like repeat is not working for me. As I said, printer is just a placeholder for another long running task (extracting a very big file).

    I posted a working example using pipes and fork in my reply above. I have not yet tested, if this will run under Windows as well. This will have to wait until tomorrow.

    BR from Germany,

    Karkadan