I had tested the following methods to execute Linux command from my program
Method 1 : Assign all into a string
String temp1 = "'/"+t2+"/,/"+t1+"/p'";
String command2 = "sed -n "+temp1+" app.log";
Process p1 = Runtime.getRuntime().exec(command2);
Method 2 : use array
String [] command2 = new String []{"sed","-n","'/",t2,"/,/",t1,"/p'", "app.log";
System.out.println("The command2 is : "+Arrays.toString(command2);
Process p2 = new ProcessBuilder(command2).start();
This my reference link for the method 2 but both of the methods not working at all. This is the command I hope to run in the terminal
sed -n '/14:32:54/,/14:33:44/p' app.log
This is a portion of my code for calling the system command, nothing displayed in line2
variable
String [] command2 = new String []{"sed","-n","'/",t2,"/,/",t1,"/p'","stlog.txt"};
Process p2 = new ProcessBuilder(command2).start();
BufferedReader br2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));
String line2;
while((line2 = br2.readLine()) != null)
{
System.out.println(line2);
}