title: Java issue command in command prompt
body: <p>I have the following class file. This start a command prompt and print the responses. weird thing is after the first print i.e. dir the subsequent doesn't print. Please advice.</p>
  
  <pre><code>import java.io.*;
  public class JavaApplication14 {
  static Process p;
  
  public static void main(String[] args) {
      try {
          String line;
  
          p = Runtime.getRuntime().exec("cmd.exe");
          OutputStream stdin = p.getOutputStream();
          InputStream stderr = p.getErrorStream();
          InputStream stdout = p.getInputStream();
  
          BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
          BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
  
          String input = "dir";
          input += "\n";
          writer.write(input);
          writer.flush();
  
  
  
          while ((line = reader.readLine()) != null) {
              System.out.println("Stdout: " + line);
          }
           input = "cd..";
          input += "\n";
          writer.write(input);
          writer.flush();
          input = "dir";
          input += "\n";
          writer.write(input);
          writer.close();
  
          while ((line = reader.readLine()) != null) {
              System.out.println("Stdout: " + line);
          }
      } catch (IOException ex) {
          Logger.getLogger(JavaApplication14.class.getName()).log(Level.SEVERE, null, ex);
      }
   }
   }
  </code></pre>