how to input password to a process waiting for password
I have created a java program in which i am using system.exec to run a dos command.
this dos command requires password input by the user after entering in command prompt.
as i am calling it through System.exec() can i enter the password with my java code.
If anyone has any idea please suggest.
thanks,
hello,
Runtime.getRuntime().exec(String command);
return a new process object for managing the subprocess. after this
you can gets the output stream of the subprocess and then pass him the password.
Process p = null;
PrintWriter pw = null;
try
{
p = Runtime.getRuntime().exec(String command);
pw = new PrintWriter(p.getOutputStream(), true /*autoflush*/);
pw.printf(password);
}
catch(Exception e)
{
e.printStackTrace();
}
by gino