views:

50

answers:

1

I want to do something like the following

<target name="complex-conditional">
  <if>
    <exec command= "python some-python-script-that-returns-true-or-false-strings-to-stout.py/>
    <then>
      <echo message="I did sometheing" />
    </then>
    <else>
      <echo message="I did something else" />
    </else>
  </if>
</target>

How do I evaluate the result of executing some script inside of an ant conditional?

+3  A: 

<exec> task has outputproperty, errorproperty and resultproperty parameters that allow you to specify property names in which to store command output / errors / result code.

You can then use one (or more) of them in your conditional statement(s):

<exec command="python some-python-script-that-returns-true-or-false-strings-to-stout.py"
      outputproperty="myout" resultproperty="myresult"/>
<if>
  <equals arg1="${myresult}" arg2="1" />
  <then>
    <echo message="I did sometheing" />
  </then>
  <else>
    <echo message="I did something else" />
  </else>
</if>
ChssPly76