【发布时间】:2012-11-29 21:11:48
【问题描述】:
我正在开发一个应用程序。我使用的操作系统是linux。如果可能,我需要在目录中创建的文件上运行 ruby 脚本。我需要让这个脚本始终运行。我首先想到的是inotify:
inotify API 提供了一种监控文件系统事件的机制。 Inotify 可用于监控单个文件,或监控目录。
这正是我所需要的,然后我找到了“rb-inotify”,它是一个 inotify 的包装器。
您认为有比使用 inotify 更好的方法来满足我的需要吗?另外,我真的不明白我必须使用 rb-inotify 的方式。
我只是创建了一个 rb 文件,例如:
notifier = INotify::Notifier.new
notifier.watch("directory/to/check",:create) do |event|
#do task with event.name file
end
notifier.run
然后我只需要ruby myRBNotifier.rb,它会一直循环播放。我该如何阻止它?任何的想法?这是一个好方法吗?
【问题讨论】:
-
我该如何阻止它? ctrl-c
-
It's exactly what I need-I need to keep this script running always...-How do I stop it?不确定问题出在哪里?