Executing a Linux shell script from Java

Main.java:

import java.io.*;
 
public class Main
{
   public static void main(String args[]) {
      try {
         Process p = Runtime.getRuntime().exec("run.sh"); 
         
         BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
 
         bw.write("1");
         bw.flush();
         String line;
         while ((line = br.readLine()) != null) {
            System.out.println(line);
         }
         br.close();
         bw.close();
 
         System.out.println(p.exitValue());
      }
      catch(Exception e) {
         System.out.println(e);
      }
   }
}

Excellent book:
Unix Shells by Example