Dear monks, as a replacement for the tail command on Windows (File::Tail doesn't work for Win32 implemetations) I tried Wheel::FollowTail from POE. To handle failures, a simple error routine is called if e.g the file "tailed" is shortend (for some reason). In case of an error, the watcher should be shut down. I ran the code in debug mode an found that no session information (wheel id, service) is available! To double check this behaviour, I tested the code with ActiveState and Strawberry Perl with same results.
POE version: 1.292 (latest) ActiveState Perl : perl 5, version 12, subversion 0 (v5.12.0) built fo +r MSWin32-x86-multi-thread, ActivePerl Build 1200 [292396], Built und +er MSWin32, Compiled at Apr 11 2010 11:30:56 Strawberry Perl: perl 5, version 12, subversion 0 (v5.12.0) built for +MSWin32-x86-multi-thread, strawberryperl 5.12.0.1 #1 Thu May 6 16:09 +:27 2010 i386, Built under MSWin32, Compiled at May 6 2010 16:31:59
The code is adopted from POE web site http://poe.perl.org/?POE_Cookbook/Watching_Logs.
#!/usr/bin/perl -w # Got from http://poe.perl.org/?POE_Cookbook/Watching_Logs use POE qw/Wheel::FollowTail/; use strict; $| = 1; my $filename = $ARGV[0]; my $filesize_after = -s "$filename"; die "Usage: $0 <filename>\n" unless $filename; die "$0: $filename: No such file or directory\n" unless -e $filename; die "$0: $filename: Permission denied\n" unless -r $filename; POE::Session->create ( inline_states => { _start => sub { $_[HEAP]->{wheel} = POE::Wheel::FollowTail->new( Filename => $_[ARG0], InputEvent => 'got_line', ErrorEvent => 'got_error', PollInterval => 1, ); $_[HEAP]->{first} = 0; }, got_line => sub { print "$_[ARG0]\n" if $_[HEAP]->{first}++ }, got_error => \&handle_log_error, }, args => [$filename], ); # Handle log errors to shut down the service. sub handle_log_error { my ($heap, $operation, $errno, $error_string, $wheel_id) = @_[HEAP, ARG0, ARG1, ARG2, ARG3]; my $service = $heap->{services}->{$wheel_id}; print "--- $service log $operation error $errno: $error_string\n"; print "--- Shutting down $service log watcher.\n"; delete $heap->{services}->{$wheel_id}; delete $heap->{watchers}->{$wheel_id}; } sub print_tail { my ($heap, $line) = @_[HEAP, ARG0]; my $filesize = -s "$heap->{wheel}->[1]"; if ( $filesize >= $filesize_after) { print "$line\n" if $_[HEAP]->{first}++; } else { handle_file_error(); } $filesize_after = -s "$heap->{wheel}->[1]"; } $poe_kernel->run();
Has anybody an idea what went wront/I did wrong? Any comments are welcome (this issue is driving me nuts 8).

Thanks a lot,
Juergen

In reply to Wheel::FollowTail - No session information available by jadams

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.