【问题标题】:ANT Script handling Return value from execANT 脚本处理 exec 的返回值
【发布时间】:2011-05-05 00:38:24
【问题描述】:

所以这就是场景。 我有

<target name="test">
  <property file="blah"></property>
  <exec dir="" executable="trast.exe" resolveexecutable="true" spawn="true">
  </exec>
</target>     

<!-- So now I have the second target that uses Return value from first target -->
<target name="test2">
  <property file="blah"></property>
  <exec dir="" executable=RETURN VALUE resolveexecutable="true" spawn="true">
  </exec>
</target>     

基本上我需要一种方法来在下一个目标中使用第一个目标的结果。我在网上查看,一种解决方案似乎是解析输出。但是有没有办法不用解析就可以得到呢?

谢谢

【问题讨论】:

    标签: scripting ant return-value exec


    【解决方案1】:

    exec 任务有一个outputproperty。你能做这样的事情吗:

    <target name="test">
      <exec dir="" executable="trast.exe" resolveexecutable="true" spawn="true" outputproperty="blah">
      </exec>
    </target>     
    
    <!-- So now I have the second target that uses Return value from first target -->
    <target name="test2">
      <exec dir="" executable="${blah}" resolveexecutable="true" spawn="true">
      </exec>
    </target>
    

    自从我使用 Ant 已经有一段时间了,我没有在这台机器上安装它,但我似乎记得做过类似上面的事情。

    或者也许使用resultproperty

    在这里找到它: http://ant.apache.org/manual/Tasks/exec.html

    【讨论】:

      【解决方案2】:

      第一个可执行文件返回您稍后必须在 test2 中运行的可执行文件的名称,对吗?

      所以第一个可执行文件可以将该名称写入脚本文件(例如 Windows 上的批处理文件,Unix 上的 shell 文件)。该脚本将有一个固定的名称,您的 Ant 脚本会运行它。

      【讨论】:

      • 嗯,它是固定的。我只是找不到从目标 test2 中的目标测试访问返回值的方法。
      • 哦,我明白了,你的意思是test返回你要执行的exe的名字?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 2020-03-12
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多