How to assign exec's output to a property in NAnt
Asked Answered
J

2

11

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

Jenks answered 18/1, 2013 at 13:28 Comment(0)
N
11

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>
Nave answered 19/1, 2013 at 8:24 Comment(2)
Thanks, I did exactly the same already. I was looking for a solution without any temp files :(Jenks
When I do this, I'm getting a carriage return in the file, which then gets transformed into '&#xD;&#xA;' Any ideas?Ysabel
M
7

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>
Marra answered 7/7, 2015 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.