I am executing Nmap in Java which saves network information to a file. The code looks like this:
Process p = Runtime.getRuntime().exec(new String[] {"nmap", "-O", "-oX", nmapFileLocation, ipStr+"/24"});
BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream()));
String line = null; while ((line = in.readLine()) != null) {}
p.waitFor();
OutputStream os = p.getOutputStream(); os.flush();
os = p.getOutputStream(); os.flush();
It seems I have to read through all of the lines to get it to work (I'm referring to the while loop); this worked for smaller networks. I tried several things to get it to run on larger networks, but it seems to hang.
For example, I am currently running the Java application that executes nMap. It has been running for half an hour and is hung where the nmap lines of code are. I have observed (many times) that if I open the file that it created, while the Java application is running, I only see the first ~12 lines in the newly-created file. However, as soon as I shut down the Java application, all ~1600 lines of the file are visible. I am willing to experiment with different approaches.