i want to get bat file output real time using java process builder
.but the problem is i'm not getting any output .how can i improve this to get output
this is my javacode
void pingIp() throws InterruptedException, IOException {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
String[] commands = {"C:\\Users\\Madhawa.se\\Desktop\\addonapp\\matrix.bat"};
ProcessBuilder process = new ProcessBuilder(commands);
process.redirectErrorStream(true);
Process shell = process.inheritIO().start();
//shell.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(shell.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(shell.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(":" + s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(":" + s);
}
} catch (IOException ex) {
Logger.getLogger(pingIo.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
t.start();
}
my actual bat file is complex so for example i use following bat file.this bat file print random numbers in intervals[1 s].so i want to get output in my java console in real time
::matrix interval //matrix.bat
@echo off
color 0a
:top
echo %random%%random%%random%%random%
ping 1.1.1.1 -n 1 -w 1000 > nul
goto top
thanks!