Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Runtime.exec() and encoding of parameter

807580Feb 18 2010 — edited Feb 18 2010
Hello,
I want to execute a shell script with parameters from a Java class. I have problems though with the encoding of the parameters which have some special characters (umlauts, accents). My java program is ran with "-Dfile.encoding=ISO-8859-1" but the variables need to be passed in UTF-8 encoding to the script. Here is a short example:
public static void main(String... aArguments) {

    try {
        String[] cmd = new String[2];
        cmd[0] = "/media/nfs/test.sh";
        cmd[1] = "Müüler";
        Process       p = Runtime.getRuntime().exec(cmd, null, null);
        int ret = p.waitFor();
    }

    catch (Exception e) {
        e.printStackTrace();
    }
}
If I run the program with
java -Dfile.encoding=ISO-8859-1 MyTest
The test.sh script will get weird characters. So how can I say that I need the "cmd" being encoded in UTF-8 ?

Thanks,
Tex
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2010
Added on Feb 18 2010
1 comment
715 views