【问题标题】:how can i run a script from Android.mk and read it's exit code (return value)我如何从 Android.mk 运行脚本并读取它的退出代码(返回值)
【发布时间】:2013-10-16 13:52:29
【问题描述】:

我正在从 Android.mk 运行一个 shell 脚本,它执行一些复制和其他操作,我想读取脚本返回的返回值,如果失败,我想停止编译。

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

我希望它是这样的:

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

【问题讨论】:

    标签: android shell compilation


    【解决方案1】:

    我认为对于您想要实现的目标,这应该可行:

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

    如果你想以赋值的方式来做,

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

    【讨论】:

      【解决方案2】:

      您可以将脚本作为正常进程运行并获取脚本返回的输入流。

          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();
          }
      

      【讨论】:

      • 你错过了这里的重点,我希望它是编译的一部分,如果脚本失败,android.mk 编译应该声明失败并停止。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多