I am trying to run split command in a Java program. When I run it in the console with argument --verbose, it prints the generated chunk as follows:
creating file 'chunk00'
creating file 'chunk01'
creating file 'chunk02'
But when I run it in a java program, these outputs will be printed after finishing the process. What I must do to get outputs while split process is running?
I've used the following code:
ProcessBuilder pb = new ProcessBuilder("split", "-a 2", "-d", "-b 52MB","--verbose",path+"/"+db,"chunk");
pb.redirectErrorStream(true);
File workingFolder = new File("/home/hajibaba");
pb.directory(workingFolder);
Process proc = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
// read the output from the command
String s = null;
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
proc.waitFor();
However, it works for a bash script that uses echo for print same results.