ANT Script handling Return value from exec

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

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

回答1:

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

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

Or maybe use resultproperty?

Found it here: 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?

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!