Writing some Java code for running a text executable file under Linux, I have a problem to print out the output of it. This executable file is actually a nmap -sP and so receives to parameters.
Everytime I call for the compiled class, I only can see the first output line but nothing else.
This is the runFile.java file:
import java.lang.Runtime;
import java.lang.Process;
import java.io.*;
import java.lang.InterruptedException;
public class runFile {
public static void main (String args[]) throws IOException, InterruptedException {
Runtime r = Runtime.getRuntime();
Process p = r.exec("/home/diegoaguilar/Dropbox/Buap/SO/file.exe "+args[0]+args[1]);
InputStream stream = p.getInputStream();
BufferedReader reader = new BufferedReader (new InputStreamReader(stream));
String salida = reader.readLine();
while (salida != null) {
System.out.println(salida);
salida = reader.readLine();
}
//p.waitFor();
}
}
So, this is the content of file.exe:
nmap -sP $segment1-$segment1
No matter what arguments, either valid or not I call runFile with, it's always printed to the console something like the first line:
Starting Nmap 5.21 ( http://nmap.org ) at 2013-08-25 02:09 CDT