@@ -193,29 +193,26 @@ public ExternalProcess start() throws UncheckedIOException {
193
193
throw new UncheckedIOException (ex );
194
194
}
195
195
196
- CircularOutputStream circular ;
197
196
try {
198
- circular = new CircularOutputStream (bufferSize );
197
+ CircularOutputStream circular = new CircularOutputStream (bufferSize );
199
198
200
199
new Thread (
201
200
() -> {
202
- InputStream input = process .getInputStream ();
203
201
// use the CircularOutputStream as mandatory, we know it will never raise a
204
202
// IOException
205
- OutputStream output = new MultiOutputStream (circular , copyOutputTo );
206
- while (process .isAlive ()) {
207
- try {
208
- // we must read the output to ensure the process will not lock up
209
- input .transferTo (output );
210
- } catch (IOException ex ) {
211
- LOG .log (
212
- Level .WARNING ,
213
- "failed to copy the output of process " + process .pid (),
214
- ex );
215
- }
203
+ try (InputStream input = process .getInputStream ();
204
+ OutputStream output = new MultiOutputStream (circular , copyOutputTo )) {
205
+ // we must read the output to ensure the process will not lock up
206
+ input .transferTo (output );
207
+ } catch (IOException ex ) {
208
+ LOG .log (
209
+ Level .WARNING , "failed to copy the output of process " + process .pid (), ex );
216
210
}
211
+ LOG .log (Level .FINE , "completed to copy the output of process " + process .pid ());
217
212
})
218
213
.start ();
214
+
215
+ return new ExternalProcess (process , circular );
219
216
} catch (Throwable t ) {
220
217
// ensure we do not leak a process in case of failures
221
218
try {
@@ -225,8 +222,6 @@ public ExternalProcess start() throws UncheckedIOException {
225
222
}
226
223
throw t ;
227
224
}
228
-
229
- return new ExternalProcess (process , circular );
230
225
}
231
226
}
232
227
0 commit comments