title: How to write "enter key pressed" to a stream?
body: <p>Sorry for this odd-sounding title...</p>
  
  <p>I have the following situation: I want my Java program to interact with an external console. In order to "send" the individual commands to that console, I need to simulate what would be an "enter key pressed" on a normal console. To clarify what I want, imagine mysql had no other API and I would need to interact via console. Although this is not my actual problem, it is close enough.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>        String command = "/usr/local/mysql/bin/mysql";
          Process child = Runtime.getRuntime().exec(command);
  
          StreamGobbler gobbler = new StreamGobbler(child.getInputStream());
          gobbler.start();
  
          BufferedWriter out = new BufferedWriter(new OutputStreamWriter(child.getOutputStream()));
          out.write("help");
          // here enter key needs to be pressed
          out.flush();
          // out.close();
  </code></pre>
  
  <p>If the call to <code>out.close()</code> is executed, everything is fine. But of course, this way I can only send a single command, which is not what I want. But if <code>out.close()</code> is omitted, the other program never executes the command. My guess is that it still waits for the command to "finish", which on a normal console would be done by pressing enter. <code>out.write(System.getProperty("line.separator"));</code> and <code>out.newLine();</code> (which are the same) do not solve the problem, neither does <code>out.write("\r\n");</code> and <code>out.write((char) 26);</code> (EOF).</p>
  
  <p>Of course, it might be, that I am doing it completely wrong (i.e., wrong approach). Then I would appreciate a pointer into the right direction...</p>
  
  <p>Any help on this highly appreciated.</p>