Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign exec's output to a property in NAnt

My aim is to fill property with output of command "git describe". I have a property:

<property name="build.version" value = ""/>

And I want to fill it with output of the following command: git describe

I tried:

<exec program='${git.executable}' outputproperty='build.version'>
  <arg value='describe' />
</exec>

but unlike the Ant, NAnt doesn't support outputproperty :( only output (to file).

like image 712
Nagg Avatar asked Jan 18 '13 13:01

Nagg


2 Answers

You're right. You have resultproperty attribute to hold the exit code and output attribute to redirect the output.

Why don't you redirect the output and load the file afterwards via loadfile task:

<target name="foo">
  <property
    name="git.output.file"
    value="C:\foo.txt" />
  <exec program="${git.executable}" output="${git.output.file}">
    <arg value="describe" />
  </exec>
  <loadfile
    file="${git.output.file}"
    property="git.output" />
</target>
like image 73
The Chairman Avatar answered Oct 25 '22 14:10

The Chairman


Using trim, you can get rid of the carriage return character at the end. For instance, in the example above, add a line at the end to trim the string

<target name="foo">
  <property
    name="git.output.file"
    value="C:\foo.txt" />
  <exec program="${git.executable}" output="${git.output.file}">
    <arg value="describe" />
  </exec>
  <loadfile
    file="${git.output.file}"
    property="git.output" />

  <property name="git.ouput.trimmed" value="${string::trim(git.output)}" />

</target>
like image 21
Prasanna Ramaswamy Avatar answered Oct 25 '22 13:10

Prasanna Ramaswamy