我想做一个脚本,监听一个等待新文件的目录,然后发送至Nextcloud。这些文件可能是大文件,所以我想在发送前检查它们是否完整。我想使用lsof +D path/to/directory,并检查文件是否在命令的输出中,如果文件不在输出中,就发送它们。代码会是这样的。
command=list()
command.append("lsof")
command.append("+D")
command.append("/path/to/dir")
lsof = subprocess.check_output(command, stderr = subprocess.STDOUT)
但我得到subprocess.CalledProcessError返回的非零退出状态1
谁能帮助执行命令并将输出结果输入变量?
EDIT:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
**kwargs).stdout
File "/usr/lib/python3.5/subprocess.py", line 708, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['lsof', '+D', '/home/CLI2Cache/sync']' returned non-zero exit status 1