title: Executing Shell Scripts from Java, Shell scripts having read operation
body: <p>I have a Shell Scripts that read the Input</p>
  
  <pre><code>#!/bin/bash
  echo "Type the year that you want to check (4 digits), followed by [ENTER]:"
  read year
  echo $year  
  </code></pre>
  
  <p>I'm executing this shell scripts using JAVA APi</p>
  
  <pre><code>ProcessBuilder pb = new ProcessBuilder("/bin/bash", "/junk/leaptest.sh");
  final Process process = pb.start();
  
  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);       
  }
  System.out.println("Program terminated!");
  </code></pre>
  
  <p>In the Java Console I can see the Output</p>
  
  <blockquote>
    <p>Type the year that you want to check (4 digits), followed by [ENTER]:</p>
  </blockquote>
  
  <p>Now the Actual Problem in How to pass the values to the Shell Scripts  in my scripts how the varialble "year" can be read               </p>
  
  <hr>
  
  <p>I have edited the code as per the suggestion but doesn't work where we correct it</p>
  
  <pre><code>ProcessBuilder pb = new ProcessBuilder("/bin/bash", "-c", "/junk/leaptest.sh");
  final Process process = pb.start();
  InputStream is = process.getInputStream();
  InputStreamReader isr = new InputStreamReader(is);
  BufferedReader br = new BufferedReader(isr);
  String line;
  /*
   * OutputStream os = process.getOutputStream(); PrintWriter pw = new
   * PrintWriter(os);
   */
  
  BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
  while ((line = br.readLine()) != null) {
      System.out.println(line);
      // pw.println("8999");
      bw.write("2012");
  }
  System.out.println("Program terminated!");
  </code></pre>