Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross platform (Linux/OS X) file system watcher (run command when file changes)

Tags:

shell

unix

I'm looking for a cross-platform (Linux and OS X) file system watcher that doesn't poll the disk for changes (or is very efficient in doing so).

This will be the core piece of a continuous integration server, and handle things such as compiling LESS/SCSS, running javascript tests, and running custom scripts. I'd like to specify a list of files and directories, and commands to execute when a file or folder changes.

I'd like something node.js, python, shell script, or ruby based.

Some of the tools I've looked at so far...

https://github.com/tafa/node-watch-tree

https://github.com/mikeal/watch/blob/master/main.js

doc.qt.nokia.com/latest/qfilesystemwatcher.html

buildr.apache.org/building.html#continuous-compilation

www.javascriptkata.com/2010/10/28/ready-js-prepare-your-javascript-for-production/

Any recommendations appreciated.

like image 615
Adam Loving Avatar asked Sep 14 '11 21:09

Adam Loving


2 Answers

Other than being written in C, entr looks like what you want.

like image 136
MicahStetson Avatar answered Sep 21 '22 15:09

MicahStetson


Cross-platform? It's very hard. I do not know any effective cross-platform implementation but, perhaps, I can suggest a starting point.

Linux has iNotify API, a kernel feature that monitors file systems and immediately alerts an attentive application to relevant events. The BSD/Mac-OS equivalent is kqueue. The two APIs seem very similar each other.

I found on CPAN, some perl wrapper for each one of them. I have no experience in python but I googled some wrapper of these APIs also in phyton. You have "only" to write your own wrapper around them to obtain your cross-platform library.

like image 23
andcoz Avatar answered Sep 19 '22 15:09

andcoz