2013-06-21 11 views
2

我有一個python腳本,它需要一個shell腳本的值。從shell腳本捕獲值並在Python中使用它,而不使用子進程

以下是shell腳本(a.sh):

#!/bin/bash 
return_value(){ 
    value=$(///some unix command) 
    echo "$value" 
} 

return_value 

以下是python腳本:

Import subprocess 
answer = Subprocess.call([‘./a.sh’]) 
print("the answer is %s % answer") 

但它不是working.The錯誤是:

ImportError : No module named subprocess

我想我的verison(Python 2.3.4)很舊。 subprocess有什麼替代品可以應用在這種情況下?

回答

4

嘗試commands模塊py2.3.​​4,注意,這個模塊已經因爲py2.6棄用:

使用commands.getoutput

import commands 
answer = commands.getoutput('./a.sh') 
+1

它的工作!!!!你如何看待這個?我知道我們的團隊需要更新我們的Python版本,但非常感謝! – user2475677

相關問題