Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Tk tail -f - How?

by BrowserUk (Pope)
on Oct 09, 2003 at 09:58 UTC ( #297862=note: print w/replies, xml ) Need Help??


in reply to Tk tail -f - How?

This one-liner will (roughtly) tail --follow a file on Win32. It always starts at the beginning, so its more of a head --follow, but that could be worked around fairly easily.

perl -e"open F, '<', $ARGV[0] or die $!; while( 1 ){ print <F>; Win32: +:Sleep 1 }" log

Currently it just outputs to the console, but you can do the Tk; bit...it might get a bit more than one line then:)

Obviously, as is you have to ^C to stop it, but with the Tk; event model, you can probably control that easily.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Tk tail -f - How?
by InfiniteSilence (Curate) on Oct 09, 2003 at 20:21 UTC
    Hey, I left this running all day, but for a file that is on a networked drive:
    perl -e"open F, $ARGV[0] or die $!; while( 1 ){ print <F>; Win32::Slee +p 1 }" f:\dev1\Logfile\Background1_08-Oct-2003-12-07-35.log
    During the day the network fouled and the drives needed to be reconnected, but the program never stopped. It just hung.

    So my question is, in this case, how would you know if the filehandle was still open and connected to the file?

    Celebrate Intellectual Diversity

      Oh! Sooo, you want your one-liner to have error recovery too:)

      I had a devil of a job trying to simulate this without a network. Eventually, I tailed (slowly) a file on a my CD drive and the opened the tray.

      Originally I had thought that using seek F, 0, 1 or die... to try and 'move' the file pointer without moving it would work but the OS noticed that the CD wasn't there and popped up a nice freindly dialogue suggesting I put it back! It might work on a network drive, it might not.

      What I came up with was using -e to check that the file is still there, which seems to work fine with my CD drive. The error is reported by perl even before the CD has stopped spinning. You'll have to tell me if this works when a networked drive becomes disconnected.

      perl -e"open F, '<', $ARGV[0] or die $!; while(1){ print <F>; -e $ARGV +[0] or die 'The file went away'; Win32::Sleep 100 }" file

      It's got a bit long for a one-liner now, but it could probably be golfed :) I keep thinking it might be possible to use <code>perl -pe"..." and defeat the eof detection, but I haven't figured out how yet.

      Any takers?


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://297862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2020-10-26 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (251 votes). Check out past polls.

    Notices?