require 'rubygems'
require 'eventmachine'
module Handler
def file_modified
puts "#{path} file modified\n Modified contents:#{get_modified_contents}"
end
end
def get_modified_contents
file1 = File.open("#{File.join(Dir.pwd,'test.txt')}",'r+')
file2_r = File.open("#{File.join(Dir.pwd,'track.txt')}",'r')
prev_pos = file2_r.read.to_i
curr_pos = file1.size
file1.seek(prev_pos)
modified_contents = file1.read
file2_w =File.open('track.txt','w')
file2_w.write(curr_pos)
modified_contents
end
EventMachine.kqueue = true if EventMachine.kqueue?
EventMachine.run {
EventMachine.watch_file("#{File.join(Dir.pwd,'test.txt')}",Handler)
}"
我正在尝试运行以上程序并收到以下错误。请提出解决方案。我安装了事件机器。
Installer/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/eventmachine- 1.0.7/lib/eventmachine.rb:1285:in `watch_filename': no file watching support on this system (EventMachine::Unsupported)
from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/eventmachine- 1.0.7/lib/eventmachine.rb:1285:in `watch_file' from C:/Users/PK64/Documents/Aptana Studio 3 Workspace/FileIO/eventmachine_prac.rb:31:in `block in <main>'
from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/eventmachine- 1.0.7/lib/eventmachine.rb:187:in `call'
from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/eventmachine- 1.0.7/lib/eventmachine.rb:187:in `run_machine'
from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
from C:/Users/PK64/Documents/Aptana Studio 3 Workspace/FileIO/eventmachine_prac.rb:30:in `<main>'