简体   繁体   English

带有utf-8字符的Runtime.exec()命令

[英]Runtime.exec() command with utf-8 characters

I'm trying to execute Runtime.getRuntime().exec() command which contains polish characters. 我正在尝试执行包含波兰语字符的Runtime.getRuntime()。exec()命令。 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(“ php / home / script / url param1 param2 param3)

execCommand looks like : execCommand看起来像:

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 然后,您可以尝试通过Runtime.exec运行它

You could also check if your JDK actually supported: 您还可以检查您的JDK是否真正支持:

Charset.forName("UTF-8")

If this fails for any reasons then there's probably something wrong/not configured in your JDK 如果由于任何原因失败,那么您的JDK中可能存在错误/未配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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