Erich Kitzmueller
Erich Kitzmueller

Reputation: 36987

Java: Runtime.getRuntime().exec() passes arguments in unicode when it shouldn't

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()?

Upvotes: 5

Views: 1613

Answers (1)

Erich Kitzmueller
Erich Kitzmueller

Reputation: 36987

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.

Upvotes: 1

Related Questions