问题
Is there any way to set an ant property by capturing the output of a shellscript? (or another ant task)
Something like this:
<property name="foo">
<value>
<exec executable="bar" />
</value>
</property>
Thanks!
回答1:
It seems that exec task has an outputproperty-property, like so:
<exec executable="bar" outputproperty="foo" />
回答2:
From the ANT exec task
- Set the
output
attribute : Name of a file to which to write the output. - As Marble has suggested - set the
outputproperty
When I tested they came out to be mutually exclusive. So set only 1 of them at a time.
回答3:
To expand on @Nim's answer, complex commands can be generated using arg
tags:
<exec executable="/usr/bin/git" outputproperty="git.branch">
<arg value="rev-parse"/>
<arg value="--abbrev-ref"/>
<arg value="HEAD"/>
</exec>
This can be referenced later like:
<attribute name="Git-Branch" value="${git.branch}"/>
来源:https://stackoverflow.com/questions/12364467/set-ant-property-by-invoking-a-shell-script