#!/usr/bin/perl -w use Tk; use strict; my $host = 'localhost'; my $mw = MainWindow->new; my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap => 'none')->pack(-expand => 1); my $button = $mw->Button(-text => 'Execute', -command => \&ping_test)->pack; MainLoop(); sub ping_test { #print "Open Filehandle\n" or die "can't fork: $!"; open (PINGTEST, "ping $host 2>&1 |") or die "can't fork: $!"; $mw->fileevent(\*PINGTEST, 'readable', [\&fill_text_widget,$t]); $button->configure(-text => 'Stop', -command => sub{ print "Close Filehandle\n"; close PINGTEST;# or die "bad ping: $! S?"; print "All done!\n"; }); } sub fill_text_widget { my($widget) = @_; $_ = ; $widget->insert('end', $_); $widget->yview('end'); }