修复执行 PreLaunchCommand 时会被阻塞的问题 (#1737)

This commit is contained in:
Akira Yamazaki
2022-09-24 16:57:19 +08:00
committed by GitHub
parent 3ed6e38ad3
commit a8b09e2195
2 changed files with 7 additions and 7 deletions

View File

@@ -27,11 +27,7 @@ import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.io.IOUtils;
import org.jackhuang.hmcl.util.io.Unzipper;
import org.jackhuang.hmcl.util.platform.CommandBuilder;
import org.jackhuang.hmcl.util.platform.JavaVersion;
import org.jackhuang.hmcl.util.platform.ManagedProcess;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jackhuang.hmcl.util.platform.Bits;
import org.jackhuang.hmcl.util.platform.*;
import org.jackhuang.hmcl.util.versioning.VersionNumber;
import java.io.*;
@@ -459,7 +455,7 @@ public class DefaultLauncher extends Launcher {
if (StringUtils.isNotBlank(options.getPreLaunchCommand())) {
ProcessBuilder builder = new ProcessBuilder(StringUtils.tokenize(options.getPreLaunchCommand())).directory(runDirectory);
builder.environment().putAll(getEnvVars());
builder.start().waitFor();
SystemUtils.callExternalProcess(builder);
}
Process process;

View File

@@ -31,7 +31,11 @@ public final class SystemUtils {
}
public static int callExternalProcess(List<String> command) throws IOException, InterruptedException {
ManagedProcess managedProcess = new ManagedProcess(new ProcessBuilder(command));
return callExternalProcess(new ProcessBuilder(command));
}
public static int callExternalProcess(ProcessBuilder processBuilder) throws IOException, InterruptedException {
ManagedProcess managedProcess = new ManagedProcess(processBuilder);
managedProcess.pumpInputStream(SystemUtils::onLogLine);
managedProcess.pumpErrorStream(SystemUtils::onLogLine);
return managedProcess.getProcess().waitFor();