Tilo's answer is the simplest. However, if you need to use "n", you're out of luck. Some searches have found this thread with some sample Java code: Java: detecting a user prompt when starting a script package from Java
I changed it for this situation, and I think it will allow you a more conservative option of using "n" as the default choice. Of course, this code can be changed in a bash script if you prefer not to have a java class working in your cron jobs, but I will leave this for someone more experienced with bash.
I have no easy way to check this code right now, so let me know how it works. :)
public static void main(final String... args) throws IOException, InterruptedException { final Runtime runtime = Runtime.getRuntime(); final String command = "..."; // cmd.exe final String matchString = "Continue with Uninstall? [Yn] "; final String response = "n"; final Process proc = runtime.exec(command, null, new File(".")); final BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream())); final BufferedWriter output = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())); StringBuilder sb = new StringBuilder(); char[] cbuf = new char[100]; while (input.read(cbuf) != -1) { sb.append(cbuf); if (sb.substring(sb.length() - matchString.length(), sb.length()).equals(matchString)) { output.write(response); output.newLine(); output.flush(); } } System.out.println(sb); }
source share