ANT脚本处理来自exec的返回值

时间:2022-10-05 18:37:44

So this is the scenario. I have

所以这就是场景。我有

<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>     

Basically I need a way to use the result from first target in the next target. I looked online and one solution seems to be is to parse output. But is there a way to get it without parsing?

基本上我需要一种方法来使用下一个目标中第一个目标的结果。我在网上看,一个解决方案似乎是解析输出。但有没有办法在没有解析的情况下获得它?

Thanks

2 个解决方案

#1


The exec task has an outputproperty. Could you do something like this:

exec任务有一个输出属性。你能做这样的事吗:

<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>

It's been a while since I used Ant and I don't have it installed on this machine, but I seem to recall doing something like the above.

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

Or maybe use resultproperty?

或者也许使用resultproperty?

Found it here: http://ant.apache.org/manual/Tasks/exec.html

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

#2


The first executable return the name of the executable that you later have to run in test2, right?

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

So the first executable could write that name into a script file (e.g. batch file on Windows, shell file on Unix). The script would have a fixed name and your Ant script would just run it.

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

#1


The exec task has an outputproperty. Could you do something like this:

exec任务有一个输出属性。你能做这样的事吗:

<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>

It's been a while since I used Ant and I don't have it installed on this machine, but I seem to recall doing something like the above.

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

Or maybe use resultproperty?

或者也许使用resultproperty?

Found it here: http://ant.apache.org/manual/Tasks/exec.html

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

#2


The first executable return the name of the executable that you later have to run in test2, right?

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

So the first executable could write that name into a script file (e.g. batch file on Windows, shell file on Unix). The script would have a fixed name and your Ant script would just run it.

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