diff --git a/common/src/main/java/net/minescript/common/SubprocessTask.java b/common/src/main/java/net/minescript/common/SubprocessTask.java index fab7161..4829007 100644 --- a/common/src/main/java/net/minescript/common/SubprocessTask.java +++ b/common/src/main/java/net/minescript/common/SubprocessTask.java @@ -11,7 +11,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; + import java.util.concurrent.TimeUnit; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -52,7 +54,7 @@ public int run(ScriptConfig.BoundCommand command, JobControl jobControl) { return -2; } - stdinWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); + stdinWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8)); var stdoutThread = new Thread(this::processStdout, Thread.currentThread().getName() + "-stdout"); @@ -82,7 +84,7 @@ public int run(ScriptConfig.BoundCommand command, JobControl jobControl) { } private void processStdout() { - try (var stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + try (var stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) { String line; while ((line = stdoutReader.readLine()) != null) { jobControl.yield(); @@ -101,7 +103,7 @@ private void processStdout() { } private void processStderr() { - try (var stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) { + try (var stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) { String line; while ((line = stderrReader.readLine()) != null) { jobControl.yield(); diff --git a/common/src/main/resources/system/lib/minescript_runtime.py b/common/src/main/resources/system/lib/minescript_runtime.py index 0b2af11..867aae2 100644 --- a/common/src/main/resources/system/lib/minescript_runtime.py +++ b/common/src/main/resources/system/lib/minescript_runtime.py @@ -22,10 +22,14 @@ import time import threading import traceback +import io from dataclasses import dataclass from typing import Any, List, Set, Dict, Tuple, Optional, Callable +if sys.stdin.encoding != 'utf-8': + sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace') + AnyConsumer = Callable[[str], None] ExceptionHandler = Callable[[Exception], None]