문제

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top