我有这样的代码:
<% Process p;
String[] cmd = "Z:\\walmart\\environment.sh";
try {
p = Runtime.getRuntime().exec(cmd);
StringBuffer s = new StringBuffer();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream)));
while (input.readLine() != null)
{
s.append(input.readLine() + "\n");
}
System.out.println(s.toString());
}
catch (IOException e) {
System.err.println("Failed to read & or start ");
}
%>
答案 0 :(得分:1)
此
String[] cmd = "Z:\walmart\environment.sh";
应该是
String[] cmd = {"Z:\walmart\environment.sh"};
这是一个字符串数组。不是char或字符串数组!
答案 1 :(得分:1)
1 - 我认为您需要转义文件路径中的反斜杠并将其设为数组:
String[] cmd = {"Z:\\walmart\\environment.sh"};
2 - 添加一般错误处理程序以找出错误:
catch (Throwable th) {
System.err.println("Error:");
th.printStackTrace();
}