2014-12-05 27 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)。

相關問題