Skip to content

Commit

Permalink
Fix launching subprocess with installed application
Browse files Browse the repository at this point in the history
  • Loading branch information
Naton1 committed Aug 14, 2022
1 parent 6203a76 commit 56380c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion explorer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.github.naton1"
version = "1.0.0"
version = "1.0.1"

repositories {
mavenCentral()
Expand Down Expand Up @@ -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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
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;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;

@Slf4j
@RequiredArgsConstructor
public class RunningJvmListCellFactory implements Callback<ListView<RunningJvm>, ListCell<RunningJvm>> {

Expand Down Expand Up @@ -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(() -> {
Expand Down

0 comments on commit 56380c0

Please sign in to comment.