gpt4 book ai didi

Python Fabric local() -exec 之后缺少语句

转载 作者:太空宇宙 更新时间:2023-11-03 18:41:35 25 4
gpt4 key购买 nike

我在使用 Python Fabric 删除一些本地文件时遇到问题。然而,我在 StackOverflow 上找到了一篇相关的文章并提供了解决方案。但我想知道为什么在最后添加 2>&1 可以解决这个问题?

我可以在终端中完美运行以下命令:

$ find app/views/-type f -name '*%%.php' -exec rm {}\;

但是,当我进行结构调用时,我得到:

$ fab rmcache
[localhost] local: find app/views/ -type f -name '*%%.php' -exec rm {} \;
find: missing argument to `-exec'

Fatal error: local() encountered an error (return code 1) while executing 'find
app/views/ -type f -name '*%%.php' -exec rm {} \;'

0:为什么通过 Fabric 需要 2>&1,而不是本地?

1:为什么可以通过 Fabric 实现这一点?

def rmcache():
local("find {0} -type f -name '*%%.php' -exec rm {{}} \ 2>&1;".format('app/views/'));

2:但这不能通过织物起作用吗?

def rmcache():
local("find {0} -type f -name '*%%.php' -exec rm {{}} \;".format('app/views/'));

最佳答案

0: 2>&1 将 stderr 重定向到 stdout,这意味着如果您的命令抛出错误,fabric 将不会拾取它,因为它没有返回到 Fabric(请参阅此 answer有关 2>&1) 的更多详细信息。

1 & 2:我的猜测是您的代码抛出错误,因为 'app/views' 是相对路径,而 find 要求目录存在,因此您必须从包含应用程序目录的目录运行 Fabric 命令。尝试使用 '/full/path/to/app/views' 确保您使用的是正确的目录。

关于Python Fabric local() -exec 之后缺少语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20392565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com