我想在LINUX中打开默认的/或xterm(任何Shell),我是用ubuntu 12.xx做的, 我可以调用xterm shell,但是当我想设置它的路径时,它会说: 错误:无法执行/“路径”:没有权限 如何设置xterm或我在JAVA中调用的任何shell的路径?
else {
String path = getCurrentFolderName().toString();
//Runtime r = Runtime.getRuntime();
String[] shellcom = {"xterm", path };
//r.exec(shellcom).waitFor();
Process p ;
ProcessBuilder builder = new ProcessBuilder();
//builder.directory(new File(path));
builder = new Process Builder(shellcom);
p = builder.start();
}
}
catch (IOException e) {
System.err.println(e.toString());
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
您应该在创建ProcessBuilder
之后设置目录。不是之前。
String[] shellcom = {"xterm"};
Process p ;
//builder.directory(new File(path)); // not here.
builder = new ProcessBuilder(shellcom);
builder.directory(new File(path)); // here.
p = builder.start();
另请注意,不应将路径添加到字符串数组shellcom
。如果你这样做,路径将作为参数传递给xterm,xterm将假定它是一个应该执行的程序,导致错误xterm: Could not exec /your/path/here: Permission denied
。