That's exactly my code. Ping comand end quickly so if i wait few seconds i have the result. Tshark capture network trafic so doesn't end.
My problem is that the reading make pauses.
This is my code :
String cmd = "c:\\\"Program Files\"\\Wireshark\\tshark.exe -T fields -e frame.len host"+ ipSrc +" and dst "+ ipDst;
String[] command = {"cmd.exe", "/C", cmd};
try {
final Process proc = Runtime.getRuntime().exec(command);
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String line = "";
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} finally {
reader.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
I also tried to use a Thread to write in terminal but it's the same problem :
new Thread() {
@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(
process.getInputStream()));
String line = "";
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} finally {
reader.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}.start();