开发者

unix shell script subprocess result

开发者 https://www.devze.com 2023-03-03 17:30 出处:网络
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'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

精彩评论

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

关注公众号