【发布时间】:2016-03-17 10:39:13
【问题描述】:
我在 Python 中有以下命令,我编写该命令的目的是仅将 .yaml 文件从 source 目录(在网络上)复制到本地 target 目录:
import subprocess as sp
cmd = ['rsync', '-rvt', "--include='*/*.yaml'", "--exclude='*/*'",
source , destination]
print ' '.join(cmd)
sp.call(cmd)
但是,当我运行这个 Python 时,所有文件都被复制了,包括 .jpg 等。
当我直接运行shell命令时:
rsync -rvt --include='*/*.yaml' --exclude='*/*' <source> <target>
...那么只有.yaml 文件被复制,正如预期的那样。
这里发生了什么?为什么命令在 shell 中的操作与在 subprocess.call 下的操作不同?
(这是在 Ubuntu 14.04 上使用 Bash shell,使用 Anaconda 的 Python 2)
【问题讨论】:
标签: python shell subprocess rsync