2014-12-05 28 views
0

在python中我试图执行fabfile,并从子进程输出中得到下面的错误。我使用简易安装来安装面料。如果我从命令行运行代码,它就可以工作。从python不行去。我认为我如何使用Popen命令存在问题?Python结构不能从python使用子进程执行

/bin/sh: 1: fab: not found 

下面是我如何开始布蟒蛇:

cmd = """fab -H 111.111.111.111 aws_bootstrap initial_chef_run:aws_server.json,aws-test,development -w """ 
os.chdir(fab_path) #change to the dir where the fabfile is located 
p = subprocess.Popen(cmd, shell=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE) 

PS我加了下面的POPEN但得到下面的错误:

executable="/bin/bash" 

/bin/bash: fab: command not found 

在命令行中我得到下面这意味着终端可以找到晶圆厂。

fab 

Fatal error: Couldn't find any fabfiles! 

Remember that -f can be used to specify fabfile path, and use -h for help. 

Aborting. 
+0

使用织物执行命令比通过popen调用fabfile更好。 – tobltobs 2014-12-05 17:49:28

+0

我会尝试删除'stdout'参数 - 然后这个命令不应该立即执行(只有当你要做的事情就像调用'p.communicate()') – robjohncox 2014-12-05 17:50:36

回答

0

尝试使用fab的整个路径。要在系统上获得工厂的路径,可以使用which fab

from fabric.tasks import execute 
import my_fabfile 

r = execute(my_fabfile.aws_bootstrap, hosts=["[email protected]%s" % '111.111.111.111]) 

返回值r将包含主机为重点的字典(:

然而,为什么Python调用工厂可能比使用晶圆厂的execute功能更好,我想不出任何理由S)。

相关问题