1

My first question. Please bear with me!

I have an Ant task that need to get some input from the user before proceeding. I use the Input task to achieve this. The input message will contain Swedish characters (eg å, ä and ö) but I am unable to get Ant to output the message properly. I'm testing this using the command line on a machine running Windows 7 Pro English (but obviously using a Swedish keyboard). Example:

<input message="åäö"/>

will output:

[input] Õõ÷

The build.xml is saved in UTF-8 format. If I do 'chcp' on the command line I get "Active code page: 850".

The same result can be seen when doing an echo:

<echo message="åäö"/>

will output:

[echo] Õõ÷

But in the case of the echo task I'm able to do:

<echo encoding="850" message=åäö">

to get the expected output:

[echo] åäö

The input task does however not have an encoding attribute and I'd very much prefer to not have to define an encoding at all, especially not on a per-task level (since I can't tell for sure on what machine the Ant script will be run from).

PS I have additional problems with the received input if it contains åäö and I set the input as a property that is later used in a filter copy task, but I guess that's a whole other question

britzl
  • 10,132
  • 7
  • 41
  • 38

1 Answers1

1

I can observe the issue on my Polish Windows.

<script language="javascript">
  java.lang.System.out.println("default charset: "
  + java.nio.charset.Charset.defaultCharset());
</script>

reports default charset as "windows-1250" while the console operates at "iso-8859-2" (I guess so).

Looks like <input> task uses the default charset thinking it would match the console input. In case it does not, I managed to override the encoding this way:

set ANT_OPTS=-Dfile.encoding=iso-8859-2
ant

In your case I would try to force 850, as it looks like JRE defaults to something else.

This question helped me to find the property name.

It is also important where ant is run from. If I run it from my ide, jedit console plugin, I don't need to override encoding, because I configured it to operate in windows-1250. So it seems to be another workaround, using an IDE.

Community
  • 1
  • 1
Jarekczek
  • 7,456
  • 3
  • 46
  • 66