3
我想從我的Groovy腳本執行python外部過程,但它不產生任何輸出。Groovy腳本無法執行外部過程
所以,作爲一個小的完整性測試我試圖簡單地輸出Python版本:
def command = """ /usr/local/bin/python -V """
def proc = command.execute()
proc.waitFor()
println "This is output: " + proc?.in?.text
以上不產生任何輸出,不過,從我的命令行我能夠運行/usr/local/bin/python -V
奇怪的是,如果我修改腳本運行identify
,那麼它確實會產生一個輸出。
def command = """ /usr/local/bin/identify --version """
def proc = command.execute()
proc.waitFor()
println "This is output: " + proc?.in?.text
什麼能導致這種行爲?
哇,永遠不會知道這一點。我的Python腳本輸出的東西使用'打印'的東西「'不工作,這就是爲什麼我嘗試'-V'。那是否會打印到標準輸出? – Anthony 2014-10-11 03:15:48
'print'語句(在PYthon 3.x中的函數)會將消息打印到標準輸出,除非您使用>> >> sys.stderr'(或Python 3.x中的'file = sys.stderr') – falsetru 2014-10-11 03:16:47