I have one shell script which has some commands, one of which command is expecting to enter some data at runtime. I am running this shell script using exec() method. Currently I am entering data manually if it asks to enter. Following is my code,
Process p = Runtime.getRuntime().exec("myshellscript");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
What I want to do is whenever console expect's data to be entered, it should be entered by java program and just continue my further java program.