Reputation: 123
I'm trying to execute a linux command in my java code. It needs to change permissions for some directory.
Here is my attempt:
String Cmd = "echo myPassword | sudo -S chmod 777 -R /home/somePath";
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(Cmd);
The command held in String Cmd
is working perfectly when I used it in terminal. But when I use it in my code nothing happens. There is no error or warning feedback that helps me to understand my mistake. What might be the problem?
Upvotes: 1
Views: 1686
Reputation: 420991
Java will not magically select bash
as your executable. You probably want to do something like
"bash -c <your command>"
See this question:
(Also the |
is a bash-thing. Java won't magically create pipes between processes.)
Upvotes: 5