i tried to run linux command from jar file, but i always get this error:
java.io.IOException: Cannot run program "ls": error=13, Permission denied.
here is my code:
String s;
Process p;
String cmd= "ls";
try {
Runtime run = Runtime.getRuntime();
p = run.exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = br.readLine()) != null){
System.out.println("line: " + s);
}
p.waitFor();
System.out.println ("exit: " + p.exitValue());
p.destroy();
} catch (Exception e) {
System.out.println(e);
}
thanks for your time.
UPDATE: For me, my solution is: i had to reinstall my OS and JDK, everything is working now.
lsthat's not an executable program. Try changing the command to"/bin/ls"String cmd= "ls -l";chmod -R 777 /folder. Then execute the jar