问题描述
我正在尝试执行包含波兰语字符的Runtime.getRuntime().exec()命令.命令从第一个波兰字母中切出.我得到的不是波兰字母,而是?".
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?
我正在使用的命令:execCommand("php/home/script/url param1 param2 param3)
Command which i'm using :execCommand("php /home/script/url param1 param2 param3)
execCommand看起来像:
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;
}
推荐答案
您可以尝试以下操作:
String command = URLEncoder.encode("<your command>", "utf-8");
然后您可以尝试通过 Runtime.exec
您还可以检查您的JDK是否真正支持:
You could also check if your JDK actually supported:
Charset.forName("UTF-8")
如果由于某种原因失败,则说明您的JDK中可能存在错误/未配置
If this fails for any reasons then there's probably something wrong/not configured in your JDK
这篇关于带有utf-8字符的Runtime.exec()命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!