在Linux薄荷上,我使用以下代码来监控我的剪贴板:
last_clip = ''
try:
while True:
clip_contents = subprocess.check_output(['xclip', '-o'])
if clip_contents != last_clip:
#write clip_contents to file
time.sleep(0.5)
except KeyboardInterrupt:
print(" Quitting...")
效果很好,除了每隔一段时间它就会挂断。我很确定它位于check_output
行,因为ps aux
表明xclip -o
是一个活跃的进程。当我用-INT
或-HUP
杀死它时,我得到了这个追溯:
Traceback (most recent call last):
File "get.py", line 16, in <module>
clip_contents = subprocess.check_output(['xclip', '-o'])
File "/usr/lib/python2.7/subprocess.py", line 544, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['xclip', '-o']' returned non-zero exit status -1
我我做错了什么,或者这里有什么车吗?