title: Getting the output stream of "cmd.exe" in Java
body: <p>I wanted to create something like a remote control for the command line in Windows.</p>
  
  <p>For this I am using a scanner, but...</p>
  
  <p>The problem is, when I read the whole line with nextLine() from the stream, the prompt will be missing (becouse is is printed, but not in a line) - and when I read the next word with next(), the line break is missing and you will lose the overview. However, some information is even missing.</p>
  
  <pre><code>package com;
  
  import java.io.IOException;
  import java.util.Scanner;
  
  public class StdinCmd extends Thread {
      public void run() {
          try {
              execute();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
      public void execute() throws IOException {
          Scanner reader = new Scanner(MainClient.getProcess().getInputStream()); // &lt;- getting the stream
          StdoutSocket stdoutSocket = new StdoutSocket();
          while (true) {
              while (reader.hasNext()) {
                  stdoutSocket.executeNext(reader.next()); // &lt;- send it to the socket (the controller). This is what will be displayed at the end.
              }
          }
      }
  }
  </code></pre>
  
  <p>I attached a screenshot of how it should look like, and how it looks at the end:</p>
  
  <p><a href="http://www.mediafire.com/?jma31ezg8ansfal" rel="nofollow">http://www.mediafire.com/?jma31ezg8ansfal</a></p>
  
  <p>I hope you can help me and I gave you enough information!</p>