title: Java: Detecting user prompt when running a batch script from Java
body: <p>I need to execute from Java a batch script, which does following</p>
  
  <p>1) Once it is started it performs a lengthy (up to several seconds) task.</p>
  
  <p>2) Thereafter, it displays a prompt "Password:".</p>
  
  <p>3) Then, the user types in the password and presses the Enter key.</p>
  
  <p>4) Then, the script completes its job.</p>
  
  <p>I know how to launch the script from Java, I know how to read output of the batch script in Java, but I don't know how to wait for the password prompt to appear (how I get to know that the batch script is awaiting the password entry).</p>
  
  <p>So, my question is: How to get to know when the batch script has printed the prompt?</p>
  
  <p>At the moment, I have following code:</p>
  
  <pre><code>final Runtime runtime = Runtime.getRuntime();
  final String command = ... ;
  
  final Process proc = runtime.exec(command, null, this.parentDirectory);
  
  final BufferedReader input = new BufferedReader(new InputStreamReader(
    proc.getInputStream()));
  
  String line = null;
  
  while ((line = input.readLine()) != null) {
   LOGGER.debug("proc: " + line);
  }
  </code></pre>