0
我無法獲取子進程的輸出。通常我會用process.getInputStream()
。但是,在這種情況下,我將子進程設置爲從父進程IO繼承。我需要這樣做,因爲子進程的輸出超出了內核設置的緩衝區,因此會掛起。我正在使用Linux btw。獲取繼承父代IO的子進程的輸出
//creating a named pipe
File fifo = fifoCreator.createFifoPipe("fifo");
String[] command = new String[] {"cat", fifo.getAbsolutePath()};
process = new ProcessBuilder(command).inheritIO().start(); //Inherit IO
FileWriter fw = new FileWriter(fifo.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(boxString);
bw.close();
process.waitFor();
fifoCreator.removeFifoPipe(fifo.toString());
//Gets nothing here
stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
String input = readAllLines(stdInput);
理想情況下,我想保留所有內容,因爲我想獲得良好的性能和較少的垃圾。
有沒有辦法將子進程的輸出重定向到某種數據結構?如果沒有,有沒有辦法獲得輸出?
我正在考慮創建一個單獨的線程來獲取輸出流。