简体   繁体   中英

Runtime.exec() command with utf-8 characters

I'm trying to execute Runtime.getRuntime().exec() command which contains polish characters. Command is cutted from the first polish letter. Instead of polish letter i'm getting "?".

How can I set correct encoding to exec this command properly?

Command which i'm using : execCommand("php /home/script/url param1 param2 param3)

execCommand looks like :

private String execCommand(String command)
{
    String output="";
    try
    {
        Process proc = Runtime.getRuntime().exec(command);
        BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        try
        {
        proc.waitFor();
        }
        catch(InterruptedException e) 
        {
            output=e.getMessage();
        }
        while(read.ready())
        {
            output=read.readLine();
        }
    }
    catch(IOException e)
    {
        output=e.getMessage();
    }

    return output;
}

You could try the following:

String command = URLEncoder.encode("<your command>", "utf-8");

You could then try to run that via Runtime.exec

You could also check if your JDK actually supported:

Charset.forName("UTF-8")

If this fails for any reasons then there's probably something wrong/not configured in your JDK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM