簡體   English   中英

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

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

我正在嘗試執行包含波蘭語字符的Runtime.getRuntime()。exec()命令。 命令從第一個波蘭字母中切出。 我得到的不是波蘭字母,而是“?”。

如何設置正確的編碼以正確執行此命令?

我正在使用的命令:execCommand(“ php / home / script / url param1 param2 param3)

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;
}

您可以嘗試以下方法:

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

然后,您可以嘗試通過Runtime.exec運行它

您還可以檢查您的JDK是否真正支持:

Charset.forName("UTF-8")

如果由於任何原因失敗,那么您的JDK中可能存在錯誤/未配置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM