问题
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;
}
回答1:
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
来源:https://stackoverflow.com/questions/15394986/runtime-exec-command-with-utf-8-characters