ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oski Wee" <oski...@hotmail.com>
Subject RE: Quotations in a property get corrupted when passed as an arg
Date Tue, 12 Apr 2005 11:08:09 GMT
Thanks Bill for the suggestion.  I tried it, but it did not work.  Maybe I 
can give a better example that illustrates the problem.

I want to pass my script an argument that has quotation marks and spaces 
inside it.

Here is the contents of my script, temp.cmd:
start "Arg1" cmd /K echo %1
start "Arg2" cmd /K echo %2
start "Arg3" cmd /K echo %3
start "Arg4" cmd /K echo %4
start "Arg5" cmd /K echo %5
start "Arg6" cmd /K echo %6

It prints out arguments in new command windows.

Here is my target:
<target name="testquote">
    <exec executable="temp.cmd" spawn="true">
        <arg value="${arg.one}" />
    </exec>
</target>

First, try setting:
    <property name="arg.one" value="argument that has a value without any 
quotes inside" />
and running the testquote target.  You will see the argument print in its 
entirety in a command window.  The other command windows for arguments 2 to 
6 will pop up and will not have any values to echo.  This is expected 
behavior.

Next, try setting:
    <property name="arg.one" value="argument that has a literal &quot; as 
part of its value" />
and running the testquote target.  The expected behavior is similar to the 
above.  Since you supply one argument, you expect one argument to print out.

But instead, the actual behavior is that the argument is truncated:
    "argument that has a literal "
and the rest of the argument is broken down to arguments 2 to 6:
    as
    part
    of
    its
    value"

I think the cause is that Ant adds quotations around the argument, not 
realizing that there is a quotation mark inside it already.  I guess ant 
makes the call to Windows like this then:

temp.cmd "argument that has a literal " as part of its value"

The above ends up getting treated like 6 arguments.  Could this be 
considered an Ant bug?

I think a better way to pass this argument would be to use escapes (yes, 
ugly, but it works):

temp.cmd argument^ that^ has^ a^ literal^ ^"^ as^ part^ of^ its^ value

The above is properly treated as 1 argument.  But this gets into Ant 
internals, I guess.

Anyway, in summary, my question is: How can you pass an argument that has 
quotations and spaces in it?

Thanks



>From: "Bill Rich" <bill@wilandra.com>
>
>An Ant file is an XML file, therefore, you need to use the XML element for
>quote marks if you want the real quote mark to appear in the target. The 
>XML
>element for quote mark is &quot;. Carefully replace only those quote marks
>that need to be passed along with this element name and it should work.
>
>HTH
>Bill Rich
>Wilandra Consulting LLC
>1325 Addiewell Place
>San Jose, CA  95120-3905
>phone:      +1 408 268-2452
>mobile:     +1 408 410-9713
>Santa Cruz: +1 831 464-9007
>fax:        +1 413 669-9716
>bill@wilandra.com
>http://www.wilandra.com
>



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


Mime
View raw message