我需要测试" ant的输出是否开始"命令是"建立成功"或"构建失败"
我的代码是:
# Start the App
sleep 20
ant -f start
if [ ! $? = 0 ] || [ "Here I have to test if ant start command output was Build Success or Build Failure" ] ; then
echo "*** Failed to start"
Exit 2
fi
答案 0 :(得分:0)
你可以这样做:
if ant -f start
then
echo "*** Build started"
else
echo "*** Failed to start"
Exit 2
fi
或者其他:
ant -f start
if [ $? -eq 0 ]
then
echo "*** Build started"
else
echo "*** Failed to start"
Exit 2
fi
答案 1 :(得分:0)
ant -f start
antRet=$?
if [ $antRet -ne 0 ];then
echo "*** Failed"
exit 1;
else
echo "*** Build started"
exit 0;
fi
答案 2 :(得分:0)
POSIX兼容:
# Start the App
sleep 20
cmd_out=$(ant -f start)
if [ $? -ne 0 ] || echo "$cmd_out" | grep -q "Build Fail"; then
echo "*** Failed to start"
exit 2
fi
如果您使用的是bash
,则输出检查更简单:
sleep 20
cmd_out=$(ant -f start)
if [[ $? != 0 || $cmd_out = Build\ Fail ]]; then
echo "*** Failed to start"
exit 2
fi