How to unmount Linux folder from Java
I tried:
final ProcessBuilder pb = new ProcessBuilder("umount", "foldername");
final Process p = pb.start();
Throws
umount: / home / user / folder_name is not in 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 cannot provide it ProcessBuilder
. Also I cannot edit fstab
(or anything else that needs to be edited) because it is a remote virus machine running on a remote server from a saved OS image.
I just want to run the command as root.
source to share
You have several options:
-
Make the control terminal accessible for the
sudo
user to enter the password there.pb = new ProcessBuilder("sh", "-c", "sudo umount foldername </dev/tty"); Process p = pb.start(); p.waitFor();
-
Run the program with
gksudo
, notsudo
. Systems that use GTK + often come with a packagegksu
as a GUI forsu
andsudo
.pb = new ProcessBuilder("gksudo","umount", "foldername");
-
Open a terminal emulator window for
sudo
:pb = new ProcessBuilder("xterm","-e","sudo","umount","foldername");
source to share