Reputation: 11257
I tried:
final ProcessBuilder pb = new ProcessBuilder("umount", "foldername");
final Process p = pb.start();
Throws
umount: /home/user/foldername is not in the fstab (and you are not root)
I tried
final ProcessBuilder pb = new ProcessBuilder("sudo","umount", "foldername");
final Process p = pb.start();
Throws
sudo: sorry, you must have a tty to run sudo
I got the root password, but can't provide it to the ProcessBuilder
. Also I cannot edit fstab
(or whatever is needed to be edited), because it is remote virutal machine started on a remote server from saved OS image.
I just want to run the command as root.
Upvotes: 3
Views: 1129
Reputation: 111279
You have a couple of options:
Make the controlling terminal available for sudo
so that the user can type the password there.
pb = new ProcessBuilder("sh", "-c", "sudo umount foldername </dev/tty");
Process p = pb.start();
p.waitFor();
Execute the program with gksudo
rather than sudo
. Systems that use GTK+ often come with the gksu
package as a graphical interface for su
and sudo
.
pb = new ProcessBuilder("gksudo","umount", "foldername");
Open a terminal emulator window for sudo
:
pb = new ProcessBuilder("xterm","-e","sudo","umount","foldername");
Upvotes: 3