title: Java Processbuilder OutputStream
body: <p>I am currently working on some kind of Remote cmd in java and i'm using ProcessBuilder to run the cmd Session. But i have the Problem that i can get the output of cmd but i dont know how to send Commands into the Running cmd Session so that they're executed.</p>
  
  <p>That's my Server code : </p>
  
  <pre><code>ServerSocket server = new ServerSocket(port);
                  while(true){
                      Socket socket = server.accept();
                      new Thread(() -&gt; {
                          try {
  
                          ProcessBuilder processBuilder = new ProcessBuilder();
                          processBuilder.command("cmd.exe");
                          Process process = processBuilder.start();
                          Thread.sleep(100);
                          process.getOutputStream().write("dir".getBytes());
  
                          while(process.isAlive() &amp;&amp; !socket.isClosed()) {
                              while(process.getInputStream().available() &gt; 0) {
                                  socket.getOutputStream().write(process.getInputStream().read());
                              }
                              while(process.getErrorStream().available() &gt; 0) {
                                  socket.getOutputStream().write(process.getErrorStream().read());
                              }
                              while(socket.getInputStream().available() &gt; 0) {
                                  System.out.println("input");
                                  process.getOutputStream().write(socket.getInputStream().read());
                              }
                          }
                          System.out.println("EXIT");
                          socket.close();
                          } catch(Exception e) {
                              e.printStackTrace();
                          }
                      }).start();
                  }
  </code></pre>
  
  <p>And this is my Client code :</p>
  
  <pre><code>Socket s = new Socket(ip, Main.CMD_PORT);
              BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
              bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
              while(!closed) {
                  String line;
                  if(s.getInputStream().available() &gt; 0 &amp;&amp; (line = br.readLine()) != null) textArea.append(line + "\n");
                  if(buffer != "")  {
                      s.getOutputStream().write(buffer.getBytes());
                      buffer = "";
                  }           
              }
              System.out.println("END");
              s.close();
              dispose();
  </code></pre>
  
  <p>The buffer contains the Commands that should be executed.
  Now When i run both, i get the following output but i cannot run Commands.</p>
  
  <pre><code>Microsoft Windows [Version 10.0.18362.657]
  (c) 2019 Microsoft Corporation. Alle Rechte vorbehalten.
  </code></pre>