我设置了 iwatch 来监控一些目录。我不想给我发电子邮件,而是想执行自己的脚本。一切顺利,直到出现一些特殊字符。
iwatch -f iwatch.xml iwatch.xml 在哪里
[...]
<path type="recursive" alert="off" events="close_write" exec="commit '%f'">/user/Desktop/test</path>
[...]
提交程序:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import chardet,sys
print 40*"-"
print chardet.detect(sys.argv[1])
print type(sys.argv[1]), sys.argv[1]
uni = unicode(sys.argv[1], sys.getfilesystemencoding())
print type(uni), uni
所以,当我运行“commit ÄÖÜäöüß”时,一切都很好
----------------------------------------
{'confidence': 0.99, 'encoding': 'utf-8'}
<type 'str'> ÄÖÜäöüß
<type 'unicode'> ÄÖÜäöüß
但是,当它从 iwatch 被触发时(触摸 ÄÖÜäöüß),我明白了
----------------------------------------
{'confidence': 0.99, 'encoding': 'utf-8'}
<type 'str'> /root/Desktop/test/ÃÃÃäöüÃ
<type 'unicode'> /root/Desktop/test/ÃÃÃäöüÃ
我对编码不太了解:/
如何在此处获取我的可读内容?
我已经尝试了我能找到的所有方法(以千种方式编码/解码),但没有弄清楚。有人可以帮我吗?每一个建议将不胜感激!非常感谢!
最佳答案
新:
这个家伙为 iwatch 写了一个补丁。
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=608843
两个提供的补丁都对我有用。
补丁 2 给出了 ...pragma is deprecated... 警告。
旧的:
更改策略,我将围绕 pyinotify 进行重建。这很好用!
import pyinotify
wm = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
print "Wrote:", event.pathname
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch('/root/Desktop/test', mask, rec=True)
notifier.loop()
关于python - (Linux) iwatch 在文件名中使用特殊字符执行 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34578048/