Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 839
Erich Kitzmueller Avatar asked Nov 15 '22 03:11

Erich Kitzmueller


1 Answers

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.

like image 61
Erich Kitzmueller Avatar answered Dec 09 '22 10:12

Erich Kitzmueller