You can use fseek () to clear the eof condition from the stream. Essentially, read to the end of the file, sleep for a while, fseek () (without changing your position) to clear eof, reading to the end of the file again. rinse, rinse, repeat. man fseek (3) for details.
This is how it looks in perl. perl seek () is essentially a wrapper for fseek (3), so the logic is the same:
wembley 0 /home/jj33/swap >
my $f = shift;
open(I, "<$f") || die "Couldn't open $f: $!\n";
while (1) {
seek(I, 0, 1);
while (defined(my $l = <I>)) {
print "Got: $l";
}
print "Hit EOF, sleeping\n";
sleep(10);
}
wembley 0 /home/jj33/swap >
This is
some
text
in
a file
wembley 0 /home/jj33/swap >
Got: This is
Got: some
Got: text
Got: in
Got: a file
Hit EOF, sleeping
Then in another session:
wembley 0 /home/jj33/swap > echo "another line of text" >> tfile
And back to the original output of the program:
Hit EOF, sleeping
Got: another line of text
Hit EOF, sleeping
source
share