2014-07-16 111 views
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(); 
    } 

} 
+0

这应该帮助。我想,你有类似的问题。 http://stackoverflow.com/questions/14684713/java-calling-bash-script-permission-denied-error – Maddy

+5

确保您的shell脚本拥有所有者,组和全局的正确执行权限。 – SpartanElite

+1

chmod + x可能会有所帮助... – Debasis

回答

0

使shell脚本可执行文件的用户

相关问题