ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Schapitz <Thomas.Schap...@ePost.de>
Subject Re: Problem with command arguments
Date Sun, 18 Jan 2004 21:34:08 GMT
Antoine Lévy-Lambert wrote:

> michelle zaremskas wrote:
>
>> I have an Ant task that I am writing which is invoking a Windows 
>> Command Line program. An example of the string I am attempting to 
>> contruct is:
>>
>>
>> pcli Put -prd:\pvcs\vm\sampledb aC:\test -o -m "My Description"  
>> -v"My Version label" bp/chess/server /chess/server/server.bat 
>> /chess/server/shutdown.txt
>>
>> The problem is I am having is that the command line executable will 
>> not allow a "space" after the -m parameter and it requires double 
>> quotes around the value I am passing.  When I attempt to construct 
>> the Command Argument using the ANT API it will either place a space 
>> after the '-m' parameter or it will place double quotes around the 
>> string like so:  "-mMy Description". 
>>
>> Can someone provide me some guidance on how I can correctly construct 
>> this string using the Ant API for my ANT task.
>>
> Hi Michelle,
>
> you should construct one command line argument object per word in your 
> command line.
>
> so -m is one argument
> My Description is one argument,
> ...

> You probably want to call CommandLine.Argument ExecTask#createArg() 
> for each argument.
>
> For instance
>
> ExecTask myExecTask() = new ExecTask();
>
> myExecTask.setExecutable("pcli");
>
> CommandLine.Argument arg1 =  myExecTask.createArg();
> arg1.setValue("-m");
>
> CommandLine.Argument arg2 =  myExecTask.createArg();
> arg2.setValue("My Description");
> ...
>
> Antoine

Hi there.
May be not exactly, what you wanted (sorry Antoine).
As you might have found out, using the manual at
      http://ant.apache.org/manual/using.html#arg
there are two posibillities to specify arguments on the exec tag:

<exec ...>
   <arg line="....all arguments in one line "/>
</exec>

<exec ...>
   <arg value="argument1"/>
   <arg value="argument2"/>
         ...
   <arg value="argumentN"/>
</exec>

 From your question, I'm guessing that you use
the second approach. (Anyway, you should
have provided the code, and the output,
ANT delivers)
Ant does *not* however, suround the individual
arguments by double or single quotes, even if it *seems*
to do so when switching to verbose mode.
(there is even a note, telling that!)
but what it does, is inserting spaces between arguments,
if you use the value="..." syntax.

What you mioght want to do is one of the following:

<exec ...>
   <arg line="....-m\"My Description\"   ... "/>
</exec>

or

<exec ...>
   <arg value="..."/>
          ....
   <arg value="-m\"My Description\""/>
         ...
   <arg value="argumentN"/>
</exec>

Note the usage of \" to place quotes into the String.

Btw, you might have ommited the quotes surounding the argument,
if ther wasn't a space in it....(depends on the program you are using,
just try...)

Cheers,
Thomas



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message