Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all. In my code below, I have a perl/Tk application with a scalebar tracking the progress of another program. The problem is that the main GUI freezes up until the tail process detects new input.

Is there a cleaner way to do this? I have experimented with File::Tail, but I get the same results.

Any help appreciated.

Regards,
Stacy.

$tpid = open(MLOG,"tail -f $log_dir/mkisofs.log |"); &log("Started mkisofs.log tail: pid = $tpid"); while ($line = <MLOG>) { if ($line =~ /estimate finish/) { $line =~ s/^\s+//; #remove leading whitespace $perc = (split(/\s+/, $line))[0]; chop($perc); #get rid of the "%" $perc = sprintf("%3.0f", $perc); $progress_label -> configure(-text => "Completed: $perc%"); $progress_scale -> set($perc); $main->update; } last if $line =~ /extents written/; } kill('TERM', $tpid); #kill the tail process close(MLOG);

Edit: chipmunk 2001-05-30

Replies are listed 'Best First'.
Re: Updating a GUI with tail???
by chb (Deacon) on May 30, 2001 at 11:58 UTC
    Try man Tk::fileevent:
    With fileevent, the process can tell when data is present and only invoke gets or read when they won't block
Re: Updating a GUI with tail???
by stefan k (Curate) on May 30, 2001 at 13:14 UTC
    Hi,
    I'm not really sure (and then it may not even belong here), but I think in perl-GTK you can achieve something like this with
    Gtk::Gdk->input_add( $source, $condition, \&function, @data );???

    Maybe some perl-gtk guru could verify this?

    Regards... Stefan

Re: Updating a GUI with tail???
by maderman (Beadle) on Jun 12, 2001 at 07:54 UTC
    Here is a way to do it without the call to unix tail... My GUI does not freeze up with this code... Regards, Stacy. my $exit = 0; for (;;) { while ($line = <MLOG>) { $main->update; if ($line =~ m/estimate finish/) { $line =~ s/^\s+//; #remove leading whitespace $perc = (split(/\s+/, $line))[0]; chop($perc); #get rid of the "%" $perc = sprintf("%3.0f", $perc); $progress_label -> configure(-text => "Percent completed: $per +c%"); $progress_scale -> set($perc); $main->update; } elsif ($line =~ /extents written/) { $exit = 1 } else { next } }#end of while last if $exit == 1; seek(MLOG,0,1); $main->update; } close(MLOG);