In my program I am executing a shell script that writes output in a file. I want to display that file contents line by line. These two operations must work simultaneously.
Here is my code:
public static void myfun(String abc) throws IOException, InterruptedException {
String customer = "xyz";
nmapoutfile=runMT.instdir+"/var/nmapout."+customer;
String nmapstatusfile = runMT.instdir+"/logs/nmapout."+customer+".log";
String nmapdonefile = runMT.instdir+"/logs/nmapout."+customer+".done";
String nmapcommand=runMT.instdir+"/bin/doscan.sh "+nmapoutfile+" "+IPRange+" "+nmapstatusfile+" "+nmapdonefile;
System.out.println(nmapcommand);
Runtime r = Runtime.getRuntime();
Process pr = r.exec(nmapcommand);
try {
BufferedReader inbr = new BufferedReader (new FileReader(new File(nmapstatusfile)));
}
catch(Exception e){
e.printStackTrace();
}
while (inbr.readLine()!=null){
System.out.println("Line is .. " + inbr.readLine());
}
pr.waitFor();
}
How do I handle concurrent read and write operation??