我需要从 Java 调用 Unix 命令。代码如下。
String strCmd = "iconv -f "+ strSrcEncoding+" -t "+ strTgtEncoding + " <<< "+"\""+InputMessage+"\"";
String commands[] = {"bash","-c",strCmd};
Process proc = Runtime.getRuntime().exec(commands);
String strData = null;
// Get the error Stream
BufferedReader brStdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
StringBuilder sbError = new StringBuilder();
// read any errors from the attempted command
while ((strData = brStdError.readLine()) != null) {
sbError.append(strData);
}
if(sbError.toString().isEmpty())
return "success";
else
return "failure"+sbError.toString();
当我传递大量数据时出现错误
"bash": java.io.IOException: error=7, Argument list too long
我尝试使用 echo 代替如下
echo <<InputMessage>> | iconv -f utf8 -t Cp930
但是遇到了同样的错误
我错过了什么吗?