python - 为什么织物使用/bin/sh

标签 python fabric

我正在尝试在远程服务器上运行一些命令。我需要在那里获取一些 bash 文件。不幸的是,fabric 似乎(突然,最近?)开始使用 /bin/sh,但由于我在我的脚本中使用了 bash 语法,所以它中断了。我找到了 this :

If shell is True (the default), run will execute the given command string via a shell interpreter, the value of which may be controlled by setting env.shell (defaulting to something similar to /bin/bash -l -c "".) Any double-quote (") or dollar-sign ($) characters in command will be automatically escaped when shell is True.

我没有改过env.shell,所以不知道fabric为什么开始使用sh。无论如何,我正在覆盖它,但仍然没有运气:

env.shell = "/bin/bash"

这可能是什么原因造成的?我可以做些什么来强制 fabric 使用bash

最佳答案

这需要一些挖掘,但这是我发现的:

可以看到 fabric 在幕后做了什么:

from   fabric.api                                        import output

FAB_SHOW_RUNNING  = True   # Show the command that fabric runs
FAB_SHOW_STDOUT   = False  # Show the stdout of the command run
FAB_SHOW_STDERR   = False  # Show the stderr of the command run
FAB_SHOW_DEBUG    = True   # Increase logging detail for messages
FAB_SHOW_USER     = True
FAB_SHOW_STATUS   = False  # Prevent fabric from using print in some situations (at least in disconnect_all)
FAB_SHOW_WARNINGS = False  # Avoid fabric from showing messages about failed commands

output['running']  = FAB_SHOW_RUNNING
output['stdout']   = FAB_SHOW_STDOUT
output['stderr']   = FAB_SHOW_STDERR
output['debug']    = FAB_SHOW_DEBUG
output['user']     = FAB_SHOW_USER
output['status']   = FAB_SHOW_STATUS
output['warnings'] = FAB_SHOW_WARNINGS

事实证明它不是使用 /bin/sh 的结构,但是,因为我(在这种特殊情况下)运行本地命令,所以罪魁祸首是 subprocess模块。为了指定要使用的shell,需要指定shell=Trueexecutable='/bin/bash'

关于python - 为什么织物使用/bin/sh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16950435/

相关文章:

python - 删除包含整数字符串的 Pandas DataFrame 行

python - Python 2.6.x 的 XML/XSL 库的选择

python - Fabric 的 cd 上下文管理器不起作用

python - 如何显示 Fabric local() 期间遇到的错误

Python Fabric 将输出保存到变量

azure - Fabric 不断要求使用 SSH 连接输入密码

python - Cloudfront 与 S3 签名 URL 和 Boto3

python - 填充 PDF 文件 - Python

python - 使用存储在另一个列表中的索引访问列表中的元素

python - 海湾合作委员会错误 : command 'gcc-4.0' failed with exit status 1