Java Runtime exec does not prohibit such a file or permission denied

My program runs on ubuntu 10.04, and here is the code:

Process process=Runtime.getRuntime().exec("ls",null,null);

it throws an exception:

Cannot run program "ls": java.io.IOException: error=2, No such file or directory,  

and I tried changing "ls" to "chmod", "pwd", I did not find any shell commands, everything came to the same problem (I also tried "/ bin / sh -c ls")

and then I change the code to:

Process process=Runtime.getRuntime().exec("/bin/ls",null,null);

it throws an exception:

Cannot run program "/bin/ls": java.io.IOException: error=13, Permission denied

I changed the privilege of all related files and directories to 777, so I really don't know what is wrong with it.

Thank you for your responses.

+5
source share
1 answer
Process process=Runtime.getRuntime().exec("ls",null,null);

, No such file or directory, ls . ls Linux, PATH, ls /bin/ls. Runtime .

"/bin/ls". @Ernest, Runtime.exec("/bin/ls") .

Process process=Runtime.getRuntime().exec("/bin/ls");

, Permission denied. Java. , /bin/ls Linux? /bin/ls ( ) 755, 777, . 777 .

, - JDK? , Unix . , Java, execute?

+2

All Articles