tags:

views:

1557

answers:

1

In Ant is there any way to do something like this:

<arguments id="arg-list">
    <arg value="arg1" />
    <arg value="arg2" />
</arguments>

<property name="prop1" refid="arg-list" />

I'm trying to write a macro for psexec and I'm looking for a nice way to pass in the argument list.

I know that you can do something similar with classpaths...

Thanks!

+2  A: 

I don't know of an answer to your specific question. The documentation is clear that refid 'Only yields reasonable results for references to PATH like structures or properties.'

Without a bit more information on what you're trying to do, it's hard to comment. At the risk of changing your design, rather than answering your question, I suggest:

1) You can pass the argument list to exec as a line:

<macrodef name="example">
  <element name="args"/>
  <sequential>
    <exec executable="example.exe">
      <arg value="somearg" />
      <arg line="@{args}"/>
    <exec>
  </sequential>
</macrodef>

<example args="somearg arg1 arg2"/>

Which will run example.exe:

example.exe arg1 arg2

2) I pass in arguments to macros that call external apps like this:

<macrodef name="example">
  <element name="params" optional="yes" implicit="yes"/>
  <sequential>
    <exec taskname="eg" executable="example.exe">
      <arg value="somearg" />
      <params />  
    </exec>  
  </sequential>
</macrodef>

<example>
  <arg value="arg1"/>
  <arg value="arg2"/>
</example>

This will run example.exe:

example.exe somearg arg1 arg2

I hope I haven't been teaching my grandmother to suck eggs here.

Richard A
The second example is what I was after. Thanks! :)
Luke Quinane
Shouldn't the elements in the <example> block be named "args" (plural, not singular) like the element parameter to the MacroDef?
Ken Gentle
Ken, if you mean in the second example, then no. As args is implicit you don't have to name it. Any elements you put in that are not explicitly associated with an element are assumed to be part of args. I'll edit the solution to use different names, to save confusion.
Richard A