我试图从我的java代码中运行.sh文件。我看到了一个类似的问题(How to run Unix shell script from Java code?),并尝试了写在那里的答案。但是,我希望进程退出值为0(正常终止),而实际上我得到了127。这是我的代码:
public int performATRs() throws IOException{
String[] command = {"sh", "/ThematicAnalysis/flexiTerm/FlexiTerm.sh"};
Process process = Runtime.getRuntime().exec(command);
InputStream inputStream = process.getInputStream();
InputStreamReader streamReader = new InputStreamReader(inputStream);
BufferedReader bufReader = new BufferedReader(streamReader);
try{
process.waitFor();
System.out.println("Waiting...");
System.out.println("Returned Value :" + process.exitValue());
}catch(InterruptedException e){
System.out.println(e.getMessage());
}
while(bufReader.ready())
System.out.println(bufReader.readLine());
return process.exitValue();
} 我试图从我的java代码中运行FlexiTerm.sh。不过,当我从终端机运行它时,它就能工作了。非常感谢你的帮助:)
发布于 2015-06-27 14:57:17
127意味着它无法执行/ThematicAnalysis/flexiTerm/FlexiTerm.sh,您应该再次检查该脚本的路径是否正确。考虑到Unix风格的系统通常不会有一个名为"ThematicAnalysis“的顶级目录,我怀疑不是这样。如果您在相对于Java程序工作目录的位置查找该脚本,则应该删除前面的正斜杠。
https://stackoverflow.com/questions/31088807
复制相似问题