开发者

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

开发者 https://www.devze.com 2023-02-07 00:58 出处:网络
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_CTY

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消