Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Tk tail -f - How?

by InfiniteSilence (Curate)
on Oct 09, 2003 at 20:21 UTC ( [id://298095]=note: print w/replies, xml ) Need Help??


in reply to Re: Tk tail -f - How?
in thread Tk tail -f - How?

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

Replies are listed 'Best First'.
Re: Re: Re: Tk tail -f - How?
by BrowserUk (Patriarch) on Oct 09, 2003 at 21:42 UTC

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://298095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found