Skip to content
Permalink
Browse files
8174768: Make ProcessTools print executed process output into a separ…
…ate file

Reviewed-by: dholmes, iignatyev
  • Loading branch information
lepestock authored and iignatev committed Mar 24, 2020
1 parent 77041dc commit 99a6b6b8487241d56c6599f24c8f40f7f963f259
Showing 1 changed file with 14 additions and 0 deletions.
@@ -29,6 +29,8 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
@@ -392,6 +394,18 @@ public static OutputAnalyzer executeProcess(ProcessBuilder pb, String input,
output = new OutputAnalyzer(p, cs);
p.waitFor();

{ // Dumping the process output to a separate file
var fileName = String.format("pid-%d-output.log", p.pid());
var processOutput = getProcessLog(pb, output);
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
Files.writeString(Path.of(fileName), processOutput);
return null;
});
System.out.printf(
"Output and diagnostic info for process %d " +
"was saved into '%s'%n", p.pid(), fileName);
}

return output;
} catch (Throwable t) {
if (p != null) {

0 comments on commit 99a6b6b

Please sign in to comment.