From 56380c001ae0ecf120a6bf97edb7ccd216bff812 Mon Sep 17 00:00:00 2001 From: Naton1 <28943608+Naton1@users.noreply.github.com> Date: Sun, 14 Aug 2022 14:26:09 -0700 Subject: [PATCH] Fix launching subprocess with installed application --- explorer/build.gradle.kts | 5 ++++- .../fx/jvms/RunningJvmListCellFactory.java | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/explorer/build.gradle.kts b/explorer/build.gradle.kts index 04e466f..36cdaef 100644 --- a/explorer/build.gradle.kts +++ b/explorer/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.github.naton1" -version = "1.0.0" +version = "1.0.1" repositories { mavenCentral() @@ -174,6 +174,9 @@ tasks { linux { linuxShortcut = true } + // We need a java.exe to launch subprocesses + // This is all the default params but without --strip-native-commands + additionalParameters = listOf("--jlink-options", "--strip-debug --no-man-pages --no-header-files") } } diff --git a/explorer/src/main/java/com/github/naton1/jvmexplorer/fx/jvms/RunningJvmListCellFactory.java b/explorer/src/main/java/com/github/naton1/jvmexplorer/fx/jvms/RunningJvmListCellFactory.java index f48c09f..8ea5793 100644 --- a/explorer/src/main/java/com/github/naton1/jvmexplorer/fx/jvms/RunningJvmListCellFactory.java +++ b/explorer/src/main/java/com/github/naton1/jvmexplorer/fx/jvms/RunningJvmListCellFactory.java @@ -18,9 +18,12 @@ import javafx.scene.image.ImageView; import javafx.util.Callback; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -28,6 +31,7 @@ import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; +@Slf4j @RequiredArgsConstructor public class RunningJvmListCellFactory implements Callback, ListCell> { @@ -123,7 +127,17 @@ private void launchJar(File selectedFile) { launchArgs.add("-jar"); launchArgs.add(selectedFile.getAbsolutePath()); try { - new ProcessBuilder().command(launchArgs).redirectErrorStream(true).inheritIO().start(); + final Process process = new ProcessBuilder().command(launchArgs).redirectErrorStream(true).start(); + // Create a new thread here, so we can log all output + new Thread(() -> { + try (final BufferedReader br = + new BufferedReader(new InputStreamReader(process.getInputStream()))) { + br.lines().forEach(line -> log.debug("Launched JVM: {}", line)); + } + catch (IOException e) { + log.warn("Exception while reading output from launched process", e); + } + }).start(); } catch (IOException ex) { Platform.runLater(() -> {