开发者

unix shell script subprocess result

i'm trying to get the result of a sub process. But for now the only result i can have is the log string. I would like to test the integer result but i don't know how.

buildresult=$(xcodebuild -project $projectfile -nodistribute -activetarget -sdk macosx10.5 "PRODUCT_VERSION_NUM=$PRODUCT_VERSION" 'MACOSX_DEPLOYMENT_TARGET=10.4' 'ARCHS=$(ARCHS_STANDARD_32_BIT)' 'DEMO_PREPROCESSOR_FLAG=_FLUX_DEMO_' "PRODUCT_NAME=$PRODUCTS_ITEM-Demo" 'BASEPRODUCT_NAME=null' -configuration Release build)

$buildresult contain the echo log, how to test the resu开发者_StackOverflow社区lt ?

Thanks.


The exit status of a subprocess is available in the $? variable:

buildresult=$(xcodebuild bla bla)
rc=$?
if test $rc -ne 0; then
    echo "NOT OK!"
    exit $rc
fi


or

buildresult=$(xcodebuild bla bla) || echo "NOT OK"


Use $? to find the return code of the last command. This assumes that the command returns a meaningful return code.

$ ls 
   :
   :
$ echo $?
0

$ dgdg
dgdg: command not found
$ echo $?
127

$ rm somefilethatdoesnotexist
rm: cannot remove `somefilethatdoesnotexist': No such file or directory
$ echo $?
1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜