3
Jenkins中的一個工作調用我的python腳本,在這個腳本中,我想調用make
來編譯我的UT代碼,並且在編譯錯誤如「make:*** [] Error時編譯sys.exit(1)
1「發生。Python調用makefile編譯並捕獲make的輸出
我還需要實時打印輸出。
這裏是我的Python腳本:
make_process = subprocess.Popen("make clean all;", shell=True, stdout=subprocess.PIPE, stderr=sys.stdout.fileno())
while True:
line = make_process.stdout.readline()
if not line:break
print line, #output to console in time
sys.stdout.flush()
但我怎麼捕捉make
錯誤,讓這個python腳本會失敗?
注:
- make_process.wait()是0時許發生錯誤。
- 這個答案並沒有爲我工作: Running shell command from Python and capturing the output
更新: 它原來是一個makefile的問題。查看接受答案的評論。但是對於這個python問題,pentadecagon給出了正確的答案。
「等待」的代碼不會爲我工作。與民意調查相同。 make_process.poll()在創建錯誤hapeens時爲0。 – liuzw
這是GNU make,對吧?檢查命令行上的返回值。如果它的值爲0,那麼你的Makefile會有些腥意。否則...也許嘗試刪除腳本中的分號? – pentadecagon
是的,GNU make。在刪除分號後它仍然不起作用。我如何檢查命令行上的返回值?謝謝 – liuzw