I am executing command from java program like
Process myProcess = Runtime.getRuntime().exec(\"sudo cat /etc/sudoers\"); //It asks for password so I send passwor
You can do it using the -S
option of sudo :
String[] cmd = {"/bash/bin","-c","echo yourpassword| sudo -S your command"};
Runtime.getRuntime.exec(cmd);
But I'm not sure it's recommendable.
I'm not the author, I found this there : http://www.coderanch.com/t/517209/java/java/provide-password-prompt-through-Java