I have an ant command for build process when I am executing that command from command prompt in between of execution it is prompting me for some password and when I enter the password and press enter key it continues the execution and giving me the successful message.
Now I want to do the same thing in java programatically using Runtime.execute(...); and it is working fine till prompting the password(I am reading the output of command prompt) but I don't know how to show a dialog box when cmd output is prompting for password where I can enter my password and with that that password my program continues the execution and complete successfully. I want to do same thing what I am doing manually from command prompt.
So question is Is it possible to enter parameters in between of command execution by Runtime.execute and how to resume the command execution passing theat paramenter if if yes how ?
It is simple a swing application which is executing the command and I want to use a Swing Ui dialog for taking password.
Updated my code as suggested by Andy Thomas :
Process p1 =Runtime.getRuntime().exec("cmd /C my command", null, myProject);
BufferedReader in = new BufferedReader(
new InputStreamReader(p1.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
if(line.contains("Please enter password")){
System.out.println("Prompting for password ");
OutputStream child_stdin = p1.getOutputStream();
BufferedWriter child_writer = new BufferedWriter(new OutputStreamWriter( child_stdin ));
child_writer.write( "password123" );
child_writer.flush();
}
}
}
But did not work.