1
我想用java程序运行我的shell脚本。我得到以下异常。从java程序运行shell脚本时被拒绝权限
java.io.IOException: Cannot run program "/home/builder/code/target/classes/idFetcher.sh": java.io.IOException: error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:605)
at java.lang.Runtime.exec(Runtime.java:443)
at java.lang.Runtime.exec(Runtime.java:340)
at script.InformationFetcher.main(InformationFetcher.java:26)
文件的路径是正确的,并且该文件存在于该位置。这里是我的代码
package script;
import java.io.IOException;
public class InformationFetcher {
public InformationFetcher() {
}
public static void main(String[] args) {
try {
InformationFetcher informationFetcher = new InformationFetcher();
Runtime.getRuntime().exec(informationFetcher.getFilePath());
} catch (IOException e) {
e.printStackTrace();
}
}
public String getFilePath() {
return this.getClass().getResource("/idFetcher.sh").getPath();
}
}
这应该帮助。我想,你有类似的问题。 http://stackoverflow.com/questions/14684713/java-calling-bash-script-permission-denied-error – Maddy
确保您的shell脚本拥有所有者,组和全局的正确执行权限。 – SpartanElite
chmod + x可能会有所帮助... – Debasis