How to provide password to the prompt through Java

Hi All,

I am using Ubuntu machine with JDK 6. I am running following command on shell-

sudo ./somecript  

. Now, it prompts for sudo password and I provide the sudo password on shell and "somescript" starts running with sudo permissions.

What I want to do is, I need to execute "sudo ./somescript" fromJava code. For that I have created a jar file which executes following command
view plaincopy to clipboardprint?

Runtime.getRuntime.exec("sudo ./somescript");

now, the problem is I dont get any prompt where I can provide the sudo password.

Please guide me to provide password to sudo.

-akash

You don't. It's specifically designed to prevent the use of plaintext passwords as a security feature -- a less-than-subtle hint that what you're attempting is a very bad idea, because stored plaintext passwords are extremely hard to keep safe. Any attempt to shoehorn one in would be very labyrinthine.

You should instead configure sudo to allow this program (and only this program) to be run without a password by this (and only this) user, and make sure this script's options prevent it being modified (so nobody puts anything untoward in it).