I'm trying to do this in Ant:
<echo message="[44;1;37mSuccess![m" />
But it doesn't work:
BUILD FAILED
./build.xml:92: Character reference "&#
How to do it?
The 0x1B character is invalid in XML contents (Invalid Characters in XML). So you need some workaround. I would go with a javascript workaround, but I give also 2 additional solutions:
<script language="javascript">
project.setNewProperty("esc", "\u001b");
</script>
<echo>${esc}</echo>
If you want the output in a file, then you could first output it using java escape \u001b
, then convert it using reverse Native2Ascii routine. Regardless of the selected encoding it always decodes \u
sequences.
<echo file="a.enc">\u001b</echo>
<native2ascii includes="a.enc" ext=".txt" dest="${basedir}"
encoding="iso-8859-1" reverse="true" />
Finally you may have the unfortunate string constant in a file:
<property file="prop.txt" />
<echo>myEsc:${myEsc}</echo>
while the prop.txt
contents is:
myEsc=\u001b
Simply use CDATA :
<project>
<echo><![CDATA[
[44;1;37mSuccess![m
]]>
</echo>
</project>
& is a special character in ant, so you should replace it with '
<echo message="&#27;[44;1;37mSuccess!&#27;[m" />