简体   繁体   English

我如何从Android.mk运行脚本并读取它的退出代码(返回值)

[英]how can i run a script from Android.mk and read it's exit code (return value)

I'm running a shell script from Android.mk which does some copying and stuff, and I want to read the return value that the script returns, if it fails, I want to halt the compilation. 我正在从Android.mk运行一个shell脚本,该脚本执行了一些复制和工作,并且我想读取该脚本返回的返回值,如果失败,我想停止编译。

$(shell $(LOCAL_PATH)/makescript.sh)

and I want it to be like this: 我希望它像这样:

value = ./makescript.sh
if value = 1 halt compilation of Android.mk file.

I think for what you'd like to achieve, this should work: 我认为对于您想要实现的目标,这应该可以工作:

ifeq (1,$(shell $(LOCAL_PATH)/makescript.sh))
$(error your error message.)
endif

And if you want to do it in the assign-value way, 如果您想以赋值方式进行操作,

return_val := $(shell $(LOCAL_PATH)/makescript.sh)
ifeq (1, $(return_val))
$(error your error message.)
endif

You can run your script as a normal process and get the input stream that is returned by your script. 您可以按常规过程运行脚本,并获取脚本返回的输入流。

    try{
        Process proccess = new ProcessBuilder( )
            .command( "path to yur script file" )
            .redirectErrorStream( true )
            .start();

        InputStream in = new BufferedInputStream( proccess.getInputStream() );
        in.close();
    }catch( IOException ioe ){
        ioe.printStackTrace();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM