1
我试图在Java程序中运行split
命令。当我在控制台参数--verbose
运行它,它打印所生成的块如下:Java在运行时输出打印输出
creating file 'chunk00'
creating file 'chunk01'
creating file 'chunk02'
但是,当我在java程序运行它,这些输出都将在完成处理后进行印刷。当split
进程正在运行时,我必须做些什么才能获得输出?
我用下面的代码:
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();
但是,它适用于使用echo
打印相同的结果bash脚本。
还必须拆分 “-a 2” 到 “-a”, “2”,也是 “-b 52MB” 改为 “-B”, “52MB” –