要监视Linux中的文件,我可以使用inotify-tools,如下所示
#!/bin/bash
# with inotify-tools installed, watch for modification of file passed as first param
while inotifywait -e modify $1; do
# do something here
done
但我如何在 OSX 中实现这一点呢?
如果您想将其包装到 Python 脚本中,可以使用 Watchdog,它适用于 Linux 和 OSX。
https://pypi.python.org/pypi/watchdog
下面是将 pyinotify 替换为 watchdog 的样子:
https://github.com/raphdg/baboon/commit/2c115da63dac16d0fbdc9b45067d0ab0960143ed
Watchdog 还有一个名为的 shell 实用程序watchmedo
:
watchmedo shell-command \
--patterns="*.py;*.txt" \
--recursive \
--command='echo "${watch_src_path}"' \
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)