#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::ROText; use IO::File; use POSIX qw/tmpnam/; use File::Basename qw/dirname/; use FindBin; # # create tempory file name: # my $File; my $Handle; my $Mw; { do { $File = tmpnam(); } until my $fh = new IO::File ($File, O_RDWR | O_CREAT | O_EXCL); } print "File: [$File]\n"; # # create $File and open $Handle: # fill_in(); system('ls', '-l', dirname($File)); open($Handle, "tail -f $File|") or die "Nope: $!"; # # Start Tk # tk_start(); exit; sub tk_start { my $mw = $Mw = new MainWindow; #$mw->title("fileevent.pl - tmpfile: [$File]"); $mw->Label( -text => "tmpfile: [$File]", -anchor => 'w', )->pack( -fill => 'x', -expand => 0, ); $mw->Button( -text => 'Daten in Datei schreiben', -command => \&fill_in, )->pack( -fill => 'x', -expand => 0, -padx => 10, -pady => 10, -ipadx => 10, ); my $t = $mw->Scrolled( 'ROText', -scrollbars => 'oe', -height => 10, -width => 50, )->pack( -fill => 'both', -expand => 1, -pady => 10, ); $mw->fileevent(\*$Handle, 'readable', [ \&fill_text_widget, $t ]); MainLoop(); } # sub tk_start sub fill_in { system("date >> $File"); } sub fill_text_widget { my ($widget) = @_; my $stat = sysread $Handle, $_, 4096; die "sysread error: $!" unless defined $stat; $widget->insert('end', $_); $widget->yview('end'); } # sub fill_text_widget END { print "Anfang vom ENDE\n"; #$Mw->fileevent(\*$Handle, 'readable'); #$Handle->close(); unlink $File or die "Konnte '$File' nicht loeschen: $!"; print "Ende vom ENDE\n"; system "kill -9 $$"; } # END