2014-10-11 3 views
3

Groovy 스크립트에서 파이썬 외부 프로세스를 실행하려고하는데 출력을 생성하지 않습니다. Groovy 스크립트가 외부 프로세스를 실행할 수 없습니다.

그래서 작은 정신 테스트로 단순히 파이썬 버전 출력 시도 : 출력을 생성하지 않습니다 위의

def command = """ /usr/local/bin/python -V """ 
    def proc = command.execute() 
    proc.waitFor() 
    println "This is output: " + proc?.in?.text 

을하지만, 내 명령 줄에서 나는 실행할 수 AM /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 

이 문제의 원인은 무엇입니까?

답변

3

python -V 명령은 버전 번호를 표준 출력 대신 표준 오류로 인쇄합니다.

$ python -V 
Python 2.7.8 
$ python -V 2>/dev/null 
$ 

그래서, 출력을 얻으려면, 표준 오류 리디렉션 (2) (1) 표준 출력 : 또는

def command = """ /usr/local/bin/python -V 2>&1 """ 
def proc = command.execute() 
proc.waitFor() 
println "This is output: " + proc?.in?.text 

, 대신 inerr를 사용할 수있는 표준 오류 출력을 얻을 :

def command = """ /usr/bin/python -V """ 
def proc = command.execute() 
proc.waitFor() 
println "This is output: " + proc?.err?.text 
+0

와우는 결코 그것을 알지 못했을 것입니다. 내 파이썬 스크립트는 뭔가'print '를 사용하여 어떤 것을 출력한다.''-v'를 시도한 이유가 작동하지 않는다. 그것은 stdout에도 인쇄됩니까? – Anthony

+0

'print' 문 (PYthon 3.x의 함수)는'>> sys.stderr' (또는 파이썬 3.x에서'file = sys.stderr')을 사용하지 않는 한 stdout에 메시지를 출력합니다 – falsetru

관련 문제