title: How to execute batch script which takes multiple inputs by using Java Process Builder?
body: <p>I have a batch script which takes input as user name and age and prints both the inputs. I want to write a java program to execute that script and pass the inputs. </p>
  
  <p>I have written the java program using ProcessBuilder. I am also passing the username and age in the process OutputStream but only user name is getting printed and age is missing. </p>
  
  <p>my script(test.bat file) :</p>
  
  <pre><code>@echo off
  echo executing test.bat
  set /p name=Enter Name: 
  set /p age=Enter Age : 
  echo Hi %name%, you are %age% years old.
  </code></pre>
  
  <p>my java program :</p>
  
  <pre><code>private static void executeInteractiveCommand(String cmd,String ... args){
      try{
          List&lt;String&gt; command = new ArrayList&lt;String&gt;();
          command.add(cmd);
          ProcessBuilder builder = new ProcessBuilder(command);
          Map&lt;String, String&gt; environ = builder.environment();
          final Process process = builder.start();
          OutputStream out = process.getOutputStream();
              out.write("tester \n\r".getBytes());
              out.flush();
  
              out.write("25\n".getBytes());
              out.flush();
              out.close();
  
              int errCode = process.waitFor();
  
              System.out.println("Process Error Code : "+errCode);
  
              InputStream is = process.getInputStream();
              InputStreamReader isr = new InputStreamReader(is);
              BufferedReader br = new BufferedReader(isr);
              String line;
              while ((line = br.readLine()) != null) {
                System.out.println(line);
              }
              //out.close();
              is.close();
              System.out.println("Program terminated!");
              }catch(IOException ex){
                  ex.printStackTrace();
              } catch(InterruptedException ex){
                  ex.printStackTrace();
              }
          }
  </code></pre>