【发布时间】:2013-11-21 06:57:09
【问题描述】:
Jenkins 中的一个工作调用我的 python 脚本,我想在其中调用 make 来编译我的 UT 代码,如果出现“make: *** [] Error 1”之类的编译错误,则引发 sys.exit(1)。
我还需要实时打印输出。
这是我的 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() 发生 make 错误时为 0。
- 这个答案对我不起作用: Running shell command from Python and capturing the output
更新: 原来是makefile问题。请参阅已接受答案的 cmets。但是对于这个python问题,pentadecagon给出了正确的答案。
【问题讨论】:
标签: python makefile subprocess