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 " 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" <[EMAIL PROTECTED]>
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 ". 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 [EMAIL PROTECTED] http://www.wilandra.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]