[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using file tail with block

Doan, Alex

4/18/2007 10:14:00 PM

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 => 10, :return_if_eof
=> 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


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

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

1 Answer

Florian Frank

4/19/2007 9:14:00 AM

0

Hi,

Doan, Alex wrote:
> 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.

--
Florian Frank