【问题标题】:Rsync from python can't fing path来自python的Rsync找不到路径
【发布时间】:2012-09-28 15:47:05
【问题描述】:

我尝试通过 Popen 和 subprocess.check_call 从 python 运行 rsync,得到了同样的错误:

subprocess.check_call(['rsync', '-au', '/opt/catflow/EpressCatalog/*', '/Users/pistacchio/dev/epress/catflow/portal/branches/noscript/frontend/static/repo/usr/2/catalogs/2/builds/ipad'])
rsync: link_stat "/opt/catflow/EpressCatalog/*" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]
*** CalledProcessError: Command '['rsync', '-au', '/opt/catflow/EpressCatalog/*', '/Users/pistacchio/dev/epress/catflow/portal/branches/noscript/frontend/static/repo/usr/2/catalogs/2/builds/ipad']' returned non-zero exit status 23

似乎问题在于它找不到(或访问)/opt/catflow/EpressCatalog/*。它不仅存在,而且从命令行运行它会得到正确的结果。

有什么帮助吗?

【问题讨论】:

  • 子流程模块有时会对参数做一些奇怪的事情。尝试将“echo”添加到列表的第一个,看看它实际运行的是什么命令。 * 可能会导致问题。
  • * 是 shell 的函数。设置shell=True 再试一次
  • echo 给出了预期的结果,我认为:rsync -au frontend/static/skeletons/EpressCatalog/* /Users/pistacchio/dev/epress/catflow/portal/branches/noscript/frontend/static/repo /usr/2/catalogs/2/builds/ipad 删除“”,我想,似乎解决了这个问题。如果您将其写为答案,我会将其标记为已接受。另外,为什么''会引起问题?谢谢

标签: python subprocess rsync


【解决方案1】:

subprocess 模块自己处理参数的引用。 当一个参数条目中有空格而不是默认引用时。

简体example

['-input', 'eggs.txt', '-output', 'spam spam.txt']

在 shell 上被称为

-input eggs.txt -output "spam spam.txt"

安全说明: 切勿使用shell=True。它打开了外壳注入攻击的风险。有关详细信息,请参阅official docu

【讨论】:

    猜你喜欢
    • 2020-05-29
    • 1970-01-01
    • 2019-04-13
    • 2021-07-12
    • 2019-05-22
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多