Using file tail with block

D

Doan, Alex

Can someone explain to me why the following raise an error? (is this
something with File::Tail::Logfile.open not closing the file upon exit?)
require 'file/tail'
File::Tail::Logfile.open('output.txt', :backward =3D> 10, :return_if_eof
=3D> true ) do |log|
log.tail { |line| puts line}
end
File.rename('output.txt', 'output2.txt')

Output:
C:/alex/work/build_process/scripts/test.rb:19:in `rename': Permission
denied - output.txt or output2
txt (Errno::EACCES)
from C:/alex/work/build_process/scripts/test.rb:19


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
While this work:
require 'file/tail'

fh =3D File::Tail::Logfile.open('output.txt', :backward =3D> 10,
:return_if_eof =3D> true )=20
fh.tail { |line| puts line }
fh.close
File.rename('output.txt', 'output2.txt')
 
F

Florian Frank

Hi,

Can someone explain to me why the following raise an error? (is this
something with File::Tail::Logfile.open not closing the file upon exit?)

Yes. Check out version 1.0.1 of File::Tail, where it is fixed. (Though
it may take some time to propagate the gem to the rubygems mirrors.)

BTW.: You're lucky, that I have found your email here, if one considers
that you didn't send it to me, and you reply-hijacked someone else's
thread in order to write to ruby-talk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top