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」 –