raHul raHul - 1 year ago 57
Bash Question

How to run a .sh file from Java?

I need to run a .sh file from my Java code with out passing any arguments. I already tried doing it with



ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh");
Process p = pb.start();

Both of the above methods didn't work. Is there any other method to run a .sh file form Java?

Answer Source
ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh", "myArg1", "myArg2");
 Process p = pb.start();
 BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
 String line = null;
 while ((line = reader.readLine()) != null)