How do I pass 2 parameters to Nant script?
Asked Answered
G

2

6

I have to write an Nant script that will accept 2 parameters on the command line. The first is just an option and has the following format: -myOption. The second one needs to be wrapped in quotes: "some value with space".

e.g. -myOption "this value"

I am new to Nant so I have unsuccessful so far and don't know how to output the command to debug.

This is what I have so far:

<target name="Build" depends="SetupConfig">
<exec workingdir="${refactory.basedir}" program="${exe.name.mfg.factory}" basedir="${refactory.basedir}" commandline="-myOption:">  
 <arg>${refactory.clientconfig}</arg>   
</exec>

I am attempting to create the command using the "commandline"' attribute and the args nested element. The args element is supposed to provide qoutes.

Can some tell me how this should look? Thanks.

Gait answered 16/2, 2010 at 14:20 Comment(0)
D
2

Try this:

<target name="Build" depends="SetupConfig">
<exec workingdir="${refactory.basedir}" program="${exe.name.mfg.factory}"  basedir="${refactory.basedir}">
    <arg value="-myOption" />
    <arg value="${refactory.clientconfig}" />
</exec>

For more information view Nant Exec task documentation.

Diminished answered 16/2, 2010 at 14:28 Comment(0)
N
29

I need to confess, looking at your code snippet it's not completely clear to me, what You are trying to achieve.

Anyway, this is how you pass two arguments to a NAnt script (what You're claiming for regarding to the question's title):

Given a NAnt script example.project.build with following content:

<?xml version="1.0"?>
<project name="example.project" default="example.target" basedir=".">
  <target name="example.target">
    <echo message="${arg.option}" />
    <echo message="${arg.whitespace}" />
  </target>
</project>

... you would call

nant -buildfile:example.project.build -D:arg.option=foo -D:arg.whitespace="bar and bar"

... to execute script example.project.build and pass arguments arg.option and arg.whitespace to it.

Nne answered 16/2, 2010 at 14:58 Comment(0)
D
2

Try this:

<target name="Build" depends="SetupConfig">
<exec workingdir="${refactory.basedir}" program="${exe.name.mfg.factory}"  basedir="${refactory.basedir}">
    <arg value="-myOption" />
    <arg value="${refactory.clientconfig}" />
</exec>

For more information view Nant Exec task documentation.

Diminished answered 16/2, 2010 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.