Reputation: 685
I need to exec the following command from ant, but I can't figure out how to escape the double-quotes:
tasklist /FI "IMAGENAME eq java.exe" /FI "MEMUSAGE gt 50000"
Upvotes: 40
Views: 48042
Reputation: 394
Ant script is xml. So in xml, here is the rule.
For > use >
For < use <
For “ use "
For & use &
For ‘ use '
Notice! ";"
Reference:
http://www.jguru.com/faq/view.jsp?EID=721755
Upvotes: 29
Reputation: 71
But doesn't work if you need to use the find
DOS command in a /CMD exec
task:
<target name="install" depends="install2">
<exec executable="cmd.exe" outputproperty="result.process">
<arg line='/c tasklist | find "httpd"'/>
</exec>
<echo message="RESULT: ${result.process}" />
</target>
gives,
install:
[exec] Current OS is Windows 7
[exec] Output redirected to property: result.process
[exec] Executing 'cmd.exe' with arguments:
[exec] '/c'
[exec] 'tasklist'
[exec] '|'
[exec] 'find'
[exec] 'httpd'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] Result: 2
[echo] RESULT: FIND : format incorrect de paramètre
Its like if ANT
deletes the double quotes around the parameter when it is passed to the CMD interpereter. The help for the find DOS function says you need to use double quotes for the text you're looking for.
Upvotes: 7
Reputation: 107040
I don't believe you really do if you use <arg value>
and not <arg line>
:
tasklist /FI "IMAGENAME eq java.exe" /FI "MEMUSAGE gt 50000"
<exec executable="tasklist">
<arg value="/FI"/>
<arg value="IMAGENAME eq java.exe"/>
<arg value="/FI"/>
<arg value="MEMUSAGE gt 50000"/>
</exec>
Despite the spaces, the <arg value>
will send it as a single parameter to the command. Unless the command itself requires quotes, this should work.
Upvotes: 20
Reputation: 175365
Ant uses XML, so you can use the normal XML entities like "
:
tasklist /FI "IMAGENAME eq java.exe" /FI "MEMUSAGE gt 50000"
Upvotes: 71
Reputation: 3563
Here is an example http://ant.apache.org/faq.html#shell-redirect-2. Simply use single quotes as xml parameter separator. This way you could freely use double quotes inside the arguments.
Upvotes: 3