title: Java - Runtime.getRuntime().exec() Key event
body: <p>There is my problem, i got a .bat who had to do : </p>
  
  <pre><code>@echo off
  echo "Hello world!"
  pause
  </code></pre>
  
  <p>My answer is, is there a way to catch the <strong>event</strong> "Press Any Key" (from an external program)  when the java program use <i>Runtime.getRuntime().exec(FullCommand)</i>?</p>
  
  <p>In my java code i use all flux (inputstream, outputstream, errorstream, into separate thread)
  and i already tryed to catch the line with a <strong>BufferedReader</strong>, but the "Press Any Key" don't come if i don't use my outputstream to simulate press key <strong>Enter</strong> with <em>newLine();</em>, because the process don't want to finish.</p>
  
  <p>So i wanted to know if there is a trick to know when the process wait or if there is a way to catch the inputstream "Press Any Key" before Enter key method, to use outputstream method after (because i don't want to use this method for all scripts that i run).</p>
  
  <blockquote>
    <p>1) <code>Run Exec</code></p>
  </blockquote>
  
  <pre><code>proc = Runtime.getRuntime().exec(FullCommand);
  try {
  Ti = new Thread(new DisplayInputStream(proc.getInputStream())); 
  Te = new Thread(new DisplayDebugStream(proc.getErrorStream()));
  
  Ti.start();
  Te.start();
  
  proc.waitFor();
  Ti.join();                                                      
  Te.join();
  }
  ......
  </code></pre>
  
  <blockquote>
    <p>2) <code>InputStream</code> method</p>
  </blockquote>
  
  <pre><code>BufferedReader br = getBufferedReader(inputStream);
  setInfosProcess(null);
  try {
      while ((StrInprocess = br.readLine()) != null) {
          if(???) //Condition Press Event key
          {
              Thread To;
              To = new Thread(new DisplayOutputStream(proc.getOutputStream()));
              To.start();
          }
          if (getInfosProcess() == null) {
              setInfosProcess(StrInprocess + "\n");
          } else {
              setInfosProcess(getInfosProcess() + StrInprocess + "\n");
          }
      }
  } 
  ......
  </code></pre>
  
  <blockquote>
    <p>3) <code>OutputStream</code> method</p>
  </blockquote>
  
  <pre><code>BufferedWriter bwr = getBufferedWriter(outputStream);
          setOutputProcess(null);
  
          try { 
              bwr.newLine();// Simulate pressing of the Enter key
              bwr.flush();// Flush the stream, otherwise it doesn't work
          } 
          ......
  </code></pre>
  
  <blockquote>
    <p>debug</p>
  </blockquote>
  
  <pre><code>        run:
          Hello world! Test:-1 //To compare string with what i want
          //"Press Any Key" from pause don't come
          //infinite loop caused by **pause**
  </code></pre>
  
  <p>Ty for any help.</p>