#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $action_F = $mw->Frame()->pack(-side => 'bottom'); $action_F->Button(-text => 'Exit', -command => sub { exit })->pack; my $text_F = $mw->Frame()->pack(-fill => 'both', -expand => 1); my $ls_T = $text_F->Scrolled('Text', -scrollbars => 'osoe', -wrap => 'none'); $ls_T->pack(-fill => 'both', -expand => 1); my $out_win = $ls_T; my $tid; my $cmd = 'ls -al 2>&1'; my $repeat = 6; my $delay = 100; $tid = $mw->repeat($delay => [\&update_ls, \$out_win, \$tid, \$cmd, \$repeat]); MainLoop; { my $updates = 0; sub update_ls { my ($text_ref, $tid_ref, $cmd_ref, $repeat_ref) = @_; $$text_ref->insert(end => scalar(localtime) . "\n" . qx{$$cmd_ref}); if (++$updates >= $$repeat_ref) { my $times_format = '(Usr: %d, Sys: %d, ChUsr: %d, ChSys: %d)'; $$text_ref->insert(end => sprintf $times_format => times); $$tid_ref->cancel; } $$text_ref->yview('end'); return; } }