Monday, 9 September 2013

How to execute bash command with sudo privileges in Java?

How to execute bash command with sudo privileges in Java?

I'm using ProcessBuilder to execute bash commands:
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
Process pb = new ProcessBuilder("gedit").start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
But I want to make something like this:
Process pb = new ProcessBuilder("sudo", "gedit").start();
How to pass superuser password to bash?
("gksudo", "gedit") will not do the trick, because it was deleted since
Ubuntu 13.04 and I need to do this with available by default commands.

No comments:

Post a Comment