我有一个 bitbake 配方,在其中我需要先检查远程服务器的可用性,然后再从远程服务器下载一些包。为此,我使用 ping,如下所示:
ping ${HOST} -c1 -w4 1>/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo "ERROR: Unable to reach ${HOST}. Exiting now with code $?..."
exit $?
fi
Run Code Online (Sandbox Code Playgroud)
上面的代码在终端中运行得很好,我得到了相应的退出代码:0 表示 OK,非零表示 NOK。
然而,与 bitbake 配方上的代码完全相同,退出代码$?始终为空。相反,bitbake 本身会捕获错误代码,然后继续执行。稍后,当尝试解压未下载的文件时,它会失败。那时,我收到了有关ping更早抛出的非零退出代码的警告。目前看起来是这样的:
if [ "$(ping ${HOST} -c1 -w4 1>/dev/null 2>/dev/null)" = 0 ]; then
echo "ERROR: Unable to reach ${HOST}. Exiting now..."
exit 1
fi
# Some other stuff here...
ar -x ${BUILDDIR}/tmp/deploy/ipk/all/rheas_*.ipk
Run Code Online (Sandbox Code Playgroud)
我得到:
ERROR: rheas-0.0-r0 do_compile: Function failed: …Run Code Online (Sandbox Code Playgroud)