try { String shellLocation = "/bin/bash"; Process p            = Runtime.getRuntime().exec(shellLocation); BufferedReader pOut  = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader pErr  = new BufferedReader(new InputStreamReader(p.getErrorStream())); DataOutputStream dos = new DataOutputStream(p.getOutputStream());  dos.writeBytes(". ~/.bashrc"+(char)10); dos.flush();  if (desiredState) { dos.writeBytes(""+installLocation+tomcatHome+"/bin/startup.sh"+(char)10); } else { dos.writeBytes(""+installLocation+tomcatHome+"/bin/shutdown.sh"+(char)10); } dos.flush(); dos.close();
try { String shellLocation = "/bin/bash"; Process p = Runtime.getRuntime().exec(shellLocation); BufferedReader pOut = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader pErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); DataOutputStream dos = new DataOutputStream(p.getOutputStream());
    public void setTomcatState(boolean desiredState) {         try {             String shellLocation = "/bin/bash";	     Process p            = Runtime.getRuntime().exec(shellLocation);	     BufferedReader pOut  = new BufferedReader(new InputStreamReader(p.getInputStream()));	     BufferedReader pErr  = new BufferedReader(new InputStreamReader(p.getErrorStream()));	     DataOutputStream dos = new DataOutputStream(p.getOutputStream());	     	     dos.writeBytes(". ~/.bashrc"+(char)10);	     dos.flush();	     //Whether the desired state is to be running or not	     if (desiredState) {	         dos.writeBytes(""+installLocation+tomcatHome+"/bin/startup.sh"+(char)10);	     } else {	         dos.writeBytes(""+installLocation+tomcatHome+"/bin/shutdown.sh"+(char)10);	     }	     dos.flush();	     dos.close();	     try {                 String out = pOut.readLine();		 while(out != null) {                     System.out.println("pOut = "+out);		     out = pOut.readLine();		 }	     } catch(IOException ioe) {                 System.out.println("IOException ioe = "+ioe);	     }	     try {                 String err = pOut.readLine();		 while(err != null) {                     System.out.println("pErr = "+err);		     err = pOut.readLine();		 }	     } catch(IOException ioe) {                 System.out.println("IOException ioe = "+ioe);	     }	 } catch(IOException ioe) {             System.out.println("IOException ioe = "+ioe);	 }    }