简体   繁体   中英

Run makefile command from bash script and return error result code

I have a python makefile. I can run its commands from my bash script as below

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.

On failure part of the output is like below

E ImportError: No module named 'serial' !!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!! =========================== 3 error in 0.17 seconds ============================ Makefile:61: recipe for target 'test-power-control' failed

$? should be return other than 0 in this case. What am I missing here? I m running the bash script in unix machine.

echo is succeeding, and thus returning 0. You have to capture the return code before running another command that may clobber $? (before the echo).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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