Reputation: 16798
Is it possible to run my program as root? I know how to run command-line native utils, but how to run Java program as root?
Upvotes: 9
Views: 44458
Reputation: 6712
This will work for you:
try {
Process process = Runtime.getRuntime().exec("su");
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
You could use this for a command:
exec(new String[] { "su", "-c", COMMAND });
Best wishes, Tim
Upvotes: 13