title: How can I write to stdIn (JAVA)
body: <p>I want to do some tests on my P2P system by using some input like: "join 8". 8 is the Node number. For my system, the command "join 8" is read from stdin, but I don't want to type it hundred times for hundred tests, so I write a test function to randomly generate node numbers and then call the "join" command by itself. So I want JAVA to write commands instead of my own input to stdin. How can I do that? 
  The goal is: When I input "test join 3", the code should randomly generate 3 node numbers between 1-255 and call join commands for them.
  My code doesn't really work now:</p>
  
  <pre><code>if (command[0].equals("test")) {
              //test join
              if (command[1].equals("join")) {
                  int nodenum = Integer.parseInt(command[2]);
                  Random rand = new Random();
                  Set&lt;Integer&gt; generated = new LinkedHashSet&lt;Integer&gt;();
                  while (generated.size() &lt; nodenum) {
                      Integer next = rand.nextInt(255) + 1;
                      generated.add(next);
                      ProcessBuilder builder = new ProcessBuilder("java", "Test");
                      Process process = builder.start();
                      //stdIn=new BufferedReader(new InputStreamReader("join"));
                      OutputStream stdin = process.getOutputStream();
                      InputStream stdout = process.getInputStream();
  
  
                      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
                      writer.write("join "+next);
                      writer.flush();
                      writer.close();
  
                  }
  
  
              }
  
          }
  </code></pre>