Debug: add stdout/stderr capture, log game logs to console
This commit is contained in:
+10
-4
@@ -62,32 +62,38 @@ public class LaunchService {
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
processBuilder.directory(instance.getPath().toFile());
|
||||
processBuilder.redirectErrorStream(true);
|
||||
|
||||
Process process = processBuilder.start();
|
||||
System.out.println("[LAUNCH] Process started, pid=" + process.pid());
|
||||
|
||||
// Capture output
|
||||
// Capture output (stdout)
|
||||
Thread outThread = new Thread(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println("[STDOUT] " + line);
|
||||
JFXLauncher.appendGameLog(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
JFXLauncher.appendGameLog("[Ошибка чтения вывода: " + e.getMessage() + "]");
|
||||
System.out.println("[STDOUT ERROR] " + e.getMessage());
|
||||
JFXLauncher.appendGameLog("[Ошибка чтения вывода: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
outThread.setDaemon(true);
|
||||
outThread.start();
|
||||
|
||||
// Capture errors
|
||||
// Capture errors (stderr)
|
||||
Thread errThread = new Thread(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println("[STDERR] " + line);
|
||||
JFXLauncher.appendGameLog("[ERR] " + line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
JFXLauncher.appendGameLog("[Ошибка чтения ошибок: " + e.getMessage() + "]");
|
||||
System.out.println("[STDERR ERROR] " + e.getMessage());
|
||||
JFXLauncher.appendGameLog("[Ошибка чтения ошибок: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
errThread.setDaemon(true);
|
||||
|
||||
@@ -41,6 +41,7 @@ public class JFXLauncher extends Application {
|
||||
private Stage mainStage;
|
||||
|
||||
public static void appendGameLog(String log) {
|
||||
System.out.println("[GAMELOG] " + log);
|
||||
synchronized (gameLogBuffer) {
|
||||
gameLogBuffer.append(log).append("\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user