Skip to content

Commit ffa8915

Browse files
committed
feat: Redirecting outputs of running subprocess to files
Signed-off-by: Richard Kocian <[email protected]>
1 parent 4fd6955 commit ffa8915

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static RemoteRobot runIde(IntelliJVersion ideaVersion, int port) {
7878

7979
String fileExtension = OS_NAME.contains("windows") ? ".bat" : "";
8080
ProcessBuilder pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion, "-Drobot-server.port=" + port);
81+
redirectProcessOutputs(pb);
8182

8283
try {
8384
ideProcess = pb.start();
@@ -308,4 +309,22 @@ private static void copyFileFromJarResourceDir(String sourceFileLocation, String
308309
LOGGER.log(Level.SEVERE, e.getMessage(), e);
309310
}
310311
}
312+
313+
/**
314+
* Redirect stdout and stderr of running subprocess to files
315+
*
316+
* @param pb Process builder of running subprocess
317+
*/
318+
private static void redirectProcessOutputs(ProcessBuilder pb) {
319+
String outDir = System.getProperty("user.home") + File.separator + "IntelliJ_debug";
320+
321+
if (!new File(outDir).mkdirs()) {
322+
LOGGER.log(Level.SEVERE, "Cannot create user.home/debug directory");
323+
}
324+
325+
File stdoutLog = new File(outDir + File.separator + "stdout.log");
326+
File stderrLog = new File(outDir + File.separator + "stderr.log");
327+
pb.redirectOutput(ProcessBuilder.Redirect.to(stdoutLog));
328+
pb.redirectError(ProcessBuilder.Redirect.to(stderrLog));
329+
}
311330
}

0 commit comments

Comments
 (0)