简体   繁体   English

从bash脚本运行makefile命令并返回错误结果代码

[英]Run makefile command from bash script and return error result code

I have a python makefile. 我有一个python makefile。 I can run its commands from my bash script as below 我可以从bash脚本运行其命令,如下所示

local make_lint_output=""
make_lint_output="$( make test-unit  2>&1 )"
echo "${make_lint_output}"

local result=$? 
if (( result == 0 )); then
    return 1
fi 

But the problem is it always return $? 但是问题是它总是返回$? as 0 even though make command exits with an error. 即使make命令错误退出,也为0。

On failure part of the output is like below 出现故障时,输出部分如下所示

E ImportError: No module named 'serial' !!!!!!!!!!!!!!!!!!! E ImportError:没有名为“ serial”的模块! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!! 中断:收集期间出现3个错误!!!!!!!!!!!!!!!!!!!!! =========================== 3 error in 0.17 seconds ============================ Makefile:61: recipe for target 'test-power-control' failed ======================================================================================================================================================================== Makefile:61:目标'test-power-control'的配方失败

$? $? should be return other than 0 in this case. 在这种情况下,应返回非0的值。 What am I missing here? 我在这里想念什么? I m running the bash script in unix machine. 我在UNIX机器上运行bash脚本。

echo is succeeding, and thus returning 0. You have to capture the return code before running another command that may clobber $? echo成功,因此返回0。在运行另一个可能破坏$?命令之前,您必须捕获返回代码$? (before the echo). (在回显之前)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM