You can do:
if ant -f start
then
echo "*** Build started"
else
echo "*** Failed to start"
Exit 2
fi
OR else:
ant -f start
if [ $? -eq 0 ]
then
echo "*** Build started"
else
echo "*** Failed to start"
Exit 2
fi
문제
I need to test if the output of "ant start" command is "Build success" or "Build Fail"
My code is:
# 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
해결책
You can do:
if ant -f start
then
echo "*** Build started"
else
echo "*** Failed to start"
Exit 2
fi
OR else:
ant -f start
if [ $? -eq 0 ]
then
echo "*** Build started"
else
echo "*** Failed to start"
Exit 2
fi
다른 팁
ant -f start
antRet=$?
if [ $antRet -ne 0 ];then
echo "*** Failed"
exit 1;
else
echo "*** Build started"
exit 0;
fi
POSIX-compatible:
# 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
If you are using bash
, the output check is simpler:
sleep 20
cmd_out=$(ant -f start)
if [[ $? != 0 || $cmd_out = Build\ Fail ]]; then
echo "*** Failed to start"
exit 2
fi