Process p=Runtime.getRuntime().exec("sudo rm -rf /home/ftp");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
bw.write("qwerty");
bw.flush();
I have written this code but it is not working
Process p=Runtime.getRuntime().exec("sudo rm -rf /home/ftp");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
bw.write("qwerty");
bw.flush();
I have written this code but it is not working
String[] cmd = {"/bash/bin","-c"," echo password| sudo -S rm -rf /home/ftp"};
Process p = Runtime.getRuntime.exec(cmd);
Provide the input for the process using the pipe.
Starting the echo
with space it will remove it from bash history.
You can also later delete the history:
new File(System.getProperty("user.home"), ".bash_history").delete();
but be careful with it. There is a trick to remove just last entries.
Assign user the required permissions and also close the buffered writer by writing
bw.close();
If you keep going for sudo mode then program may delete some important files that are required by other applications to work in a healthy way.