从java程序运行shell脚本时权限被拒绝 [英] Permission denied when running shell script from java program

查看:2062
本文介绍了从java程序运行shell脚本时权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用java程序运行我的shell脚本。我得到以下异常。

I am trying to run my shell script using java program. I am getting following exception.

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)

文件的路径是正确的,文件存在于该位置。这是我的代码

The path of file is correct and file is present at that location. Here is my code

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();
    }

}


推荐答案

使shell脚本可执行用户

Make the shell script executable for the user

这篇关于从java程序运行shell脚本时权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆