How to make pyinotify to run the program with any changes to the file?

I need to keep track of any entered entries or any changes made to the actual content on top of the file, with any changes I need to run the python program located in the same folder.

I tried my best to understand, but I can’t get a good result. It would be very helpful if anyone could help me with this.

Thank..:)

+5
source share
2 answers
import pyinotify,subprocess
def onChange(ev):
    cmd = ['/bin/echo', 'File', ev.pathname, 'changed']
    subprocess.Popen(cmd).communicate()
wm = pyinotify.WatchManager()
wm.add_watch('file.watched', pyinotify.IN_MODIFY, onChange)
notifier = pyinotify.Notifier(wm)
notifier.loop()

Replace with the cmdcommand you want to execute and file.watchedwith the file you want to see, obviously.

+9
source

from http://schettino72.wordpress.com/tag/inotify/

inotify doit. . Inotify , Pyinotify python. , . , -...

, "". Emacs, 3 . VIM , !

phihag

wm.add_watch('file.watched', pyinotify.IN_MODIFY, onChange)

:

wm.add_watch('file.watched', pyinotify.IN_CLOSE_WRITE, onChange)
+2

All Articles