title: Java process swing InputStream and OutputStream operations
body: <p>I have <code>slcanterm.exe</code> command line utility that perform terminal functions with my USB-CAN adapter, connected to PC.
  I need to start this utility from Java application, then in loop write and read to/from this terminal.
  My problem is that I can't get InputStream and OutputStream worked together:</p>
  
  <pre><code>System.out.println( "hello" );
  String line;
  OutputStream stdin = null;
  InputStream stderr = null;
  InputStream stdout = null;
  
  Process process = Runtime.getRuntime ().exec ("cmd.exe");
  stdin = process.getOutputStream ();
  stderr = process.getErrorStream ();
  stdout = process.getInputStream ();
  
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
  BufferedReader reader = new BufferedReader (new InputStreamReader (stdout));
  
  line = "slcanterm.exe" + "\n";
  writer.write(line );
  writer.flush();
  
  // If I uncomment this line reader.readLine() loop is stucked
  //writer.close();
  
  while ((line = reader.readLine ()) != null)     
      System.out.println ("[Stdout] " + line);
  
  System.out.println( "buy" );
  </code></pre>
  
  <p>If I not close <code>writer</code> stream the <code>while ((line = reader.readLine ()) != null)</code>
  stay stucked.
  I need perform to work <code>reader.readLine ()</code> and <code>writer.write(line )</code> together in loop.
  Is there any solutions?</p>