You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dave Westerman <dl...@us.ibm.com> on 2013/11/06 02:06:15 UTC
Issues With Quotes
I have a problem with double-quotes in Ant, and I'm not sure how to get
around the problem.
I'm passing in an attribute that contains a value to search for in a file
in Windows. I'm doing this:
<exec executable="cmd.exe"
resultproperty="retcode"
outputproperty="output">
<arg line="/c findstr /c:"@{value}" @{file}" />
</exec>
>From the command line, the findstr command can handle a quote in the data;
for instance, this works to find a quote in the file:
> findstr /c:"""
However, Ant chokes when it encounters any quotes in the data I am passing
to the macro via the '@{value}' argument. I have tried the following in
the '@{value}' argument:
" - unbalanced quote error
"" - no syntax error, but doesn't work, because it's looking for two
quotes
\" - unbalanced quote error
\\" - unbalanced quote error
Any ideas how I can handle quotes in the '@{value}' argument? I will never
know beforehand what may be in it.
Thanks!
Re: Issues With Quotes
Posted by Dave Westerman <dl...@us.ibm.com>.
Earl, thanks, that did it! I didn't even have to change the quotes on it,
it worked just like this:
<arg value=""@{file}"" />
Having said all that, I actually changed this particular code to use the
Ant 'resourcecontains' condition instead, when it hit me that I didn't
need to use a Windows command for this.
Thanks!
DLW
From: Earl Hood <ea...@earlhood.com>
To: Ant Users List <us...@ant.apache.org>,
Date: 11/05/2013 08:23 PM
Subject: Re: Issues With Quotes
Sent by: earlhood@gmail.com
On 11/5/13, Dave Westerman wrote:
> I'm passing in an attribute that contains a value to search for in a
file
> in Windows. I'm doing this:
>
> <exec executable="cmd.exe"
> resultproperty="retcode"
> outputproperty="output">
> <arg line="/c findstr /c:"@{value}" @{file}" />
> </exec>
I normally avoid using <arg line> since some additional parsing is done
by Ant (or the sub-shell), and it may mess things up. Break up the
arguments like the following to see if things work:
<exec executable="cmd.exe"
resultproperty="retcode"
outputproperty="output">
<arg value="/c" />
<arg value="findstr" />
<arg value='/c:"@{value}"' />
<arg value="@{file}" />
</exec>
Note, not sure if the double-quotes are still required around @{value}
or not, you will have to test things out. Windows batch (cmd.exe)
syntax is ugly, especially when dealing with quotes.
--ewh
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Issues With Quotes
Posted by Earl Hood <ea...@earlhood.com>.
On 11/5/13, Dave Westerman wrote:
> I'm passing in an attribute that contains a value to search for in a file
> in Windows. I'm doing this:
>
> <exec executable="cmd.exe"
> resultproperty="retcode"
> outputproperty="output">
> <arg line="/c findstr /c:"@{value}" @{file}" />
> </exec>
I normally avoid using <arg line> since some additional parsing is done
by Ant (or the sub-shell), and it may mess things up. Break up the
arguments like the following to see if things work:
<exec executable="cmd.exe"
resultproperty="retcode"
outputproperty="output">
<arg value="/c" />
<arg value="findstr" />
<arg value='/c:"@{value}"' />
<arg value="@{file}" />
</exec>
Note, not sure if the double-quotes are still required around @{value}
or not, you will have to test things out. Windows batch (cmd.exe)
syntax is ugly, especially when dealing with quotes.
--ewh
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org