为什么不面料看到我的.bash_profile? [英] Why doesn't Fabric see my .bash_profile?

查看:178
本文介绍了为什么不面料看到我的.bash_profile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在面料,当我尝试使用任何别名或从我的的.bash_profile 文件的功能,他们不承认。比如我的的.bash_profile 包含别名C ='workon Django的加拿大,所以当我键入<$ C $ ç> C 中的iTerm或终端, workon Django的加拿大执行

In Fabric, when I try to use any alias' or functions from my .bash_profile file, they are not recognized. For instance my .bash_profile contains alias c='workon django-canada', so when I type c in iTerm or Terminal, workon django-canada is executed.

我的 fabfile.py 包含

def test():
    local('c')

但是当我尝试晶圆厂测试它抛出这个我:
    [本地主机]地方:C

But when I try fab test it throws this at me: [localhost] local: c

/bin/sh: c: command not found

Fatal error: local() encountered an error (return code 127) while executing 'c'

Aborting.

其他面料功能正常工作。我必须某处指定面料我的bash的个人资料?

Other Fabric functions work fine. Do I have to specify my bash profile somewhere in fabric?

推荐答案

编辑 - 事实证明,这种固定在织物1.4.4。从更新日志:

EDIT - As it turns out, this was fixed in Fabric 1.4.4. From the changelog:

[专题] #725 :更新本地允许覆盖,其中用于本地shell。感谢穆斯塔法·哈塔卜。

[Feature] #725: Updated local to allow override of which local shell is used. Thanks to Mustafa Khattab.

所以,原来的问题将是固定这样的:

So the original question would be fixed like this:

def test():
    local('c', shell='/bin/bash')

我已经离开我的下面原来的答复,只涉及到面料版本&LT; 1.4.4。

I've left my original answer below, which only relates to Fabric version < 1.4.4.

由于当地不使用bash。您可以在输出清楚地看到它。

Because local doesn't use bash. You can see it clearly in your output

/bin/sh: c: command not found

看到了吗?它使用 / bin / sh的而不是 /斌/庆典。这是因为面料的本地命令的行为稍有不同的内部比运行。在本地命令基本上是围绕 subprocess.Popen Python类的包装。

See? It's using /bin/sh instead of /bin/bash. This is because Fabric's local command behaves a little differently internally than run. The local command is essentially a wrapper around the subprocess.Popen python class.

<一个href=\"http://docs.python.org/library/subprocess.html#popen-constuctor\">http://docs.python.org/library/subprocess.html#popen-constuctor

这是你的问题。 POPEN默认为 / bin / sh的。这是可能的,如果指定您呼叫的构造器POPEN自己不同的外壳,但你使用它通过面料。不幸的是你,面料让你没有办法在shell来传递,如 /斌/庆典

And here's your problem. Popen defaults to /bin/sh. It's possible to specify a different shell if you are calling the Popen constructor yourself, but you're using it through Fabric. And unfortunately for you, Fabric gives you no means to pass in a shell, like /bin/bash.

对不起,这并不为您提供一个解决方案,但它应该回答你的问题。

Sorry that doesn't offer you a solution, but it should answer your question.

修改

下面是有问题的code,直接从面料的拉中定义的本地功能 operations.py 文件:

Here is the code in question, pulled directly from fabric's local function defined in the operations.py file:

p = subprocess.Popen(cmd_arg, shell=True, stdout=out_stream,
    stderr=err_stream)
(stdout, stderr) = p.communicate()

正如你所看到的,它不会在任何可执行关键字通过。这将导致它使用默认值,这是/ bin / sh的。如果使用bash中,它会是这样的:

As you can see, it does NOT pass in anything for the executable keyword. This causes it to use the default, which is /bin/sh. If it used bash, it'd look like this:

p = subprocess.Popen(cmd_arg, shell=True, stdout=out_stream,
    stderr=err_stream, executable="/bin/bash")
(stdout, stderr) = p.communicate()

但事实并非如此。这就是为什么他们说本地的文档中的以下内容:

But it doesn't. Which is why they say the following in the documentation for local:

地方简直是周围使用内建的Python的子进程模块与壳= TRUE激活的方便包装。如果你需要做什么特别的事情,可以考虑直接使用子进程模块。

local is simply a convenience wrapper around the use of the builtin Python subprocess module with shell=True activated. If you need to do anything special, consider using the subprocess module directly.

这篇关于为什么不面料看到我的.bash_profile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆