5

My problem is best explained in an example: The following program is run on a Linux system that is not in Unicode mode yet, but in ISO-8859-15. The environment is set as follows: LC_CTYPE=de_DE@euro

import java.io.*;
import java.util.*;

public class UnicodeTest {
    public static void main(String[] args) throws Exception {
            Runtime.getRuntime().exec(new String[] { "foobar", "äöü" });
    }
}

When I compile this program in the command line using javac and run it, foobar gets the argument äöü correctly, in ISO-8859-1. The same program, run from Netbeans, passes the argument as Unicode, thus making it unusable in the called program. The same happens in Tomcat when that method is called. Which setting or environment variable uses Java to determine how to pass arguments in Runtime.exec()?

Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102
  • "when it shouldn't" - isn't that redundant. Would you ever want it to pass them incorrectly. ;) Have you checked how netbeans saves your file? Netbeans uses javac to do the compiling so it should compile the same. – Peter Lawrey Jan 28 '11 at 09:40
  • Peter: Thanks, corrected the title. I will check if Netbeans creates the same class files, I guess it does. – Erich Kitzmueller Jan 28 '11 at 09:45
  • Checked that. Running from Netbeans generates the wrong result. Running the same class file (built by Netbeans) in the command line generates the right result. – Erich Kitzmueller Jan 28 '11 at 09:51

1 Answers1

1

Found it. The behaviour is controlled by the system property file.encoding. Netbeans sets it to UTF-8. In the command line, it's ISO-8859-15.

Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102