diff --git a/astrbot/cli/commands/cmd_service.py b/astrbot/cli/commands/cmd_service.py index 91e28f2dd..0fe6f0a3a 100644 --- a/astrbot/cli/commands/cmd_service.py +++ b/astrbot/cli/commands/cmd_service.py @@ -366,6 +366,8 @@ def _build_windows_powershell_arguments( script = ( "$ErrorActionPreference = 'Stop'\n" "$env:PYTHONUNBUFFERED = '1'\n" + "$env:PYTHONUTF8 = '1'\n" + "$env:PYTHONIOENCODING = 'utf-8'\n" "$cmdExe = if ($env:COMSPEC) { $env:COMSPEC } else { 'cmd.exe' }\n" f"$astrbotCommand = {_quote_powershell_literal(_build_windows_cmd_line(service_name, executable))}\n" "$process = Start-Process " diff --git a/tests/test_cli_service.py b/tests/test_cli_service.py index a76d040ed..5c192362a 100644 --- a/tests/test_cli_service.py +++ b/tests/test_cli_service.py @@ -146,6 +146,9 @@ def test_windows_task_xml_uses_astrbot_executable_and_working_directory(): assert "powershell.exe" in task_xml assert "true" in task_xml assert "-WindowStyle Hidden" in task_xml + assert "$env:PYTHONUNBUFFERED = '1'" in powershell_script + assert "$env:PYTHONUTF8 = '1'" in powershell_script + assert "$env:PYTHONIOENCODING = 'utf-8'" in powershell_script assert "Start-Process" in powershell_script assert "-WindowStyle Hidden" in powershell_script assert "C:\\Users\\astrbot\\.local\\bin\\astrbot.exe" in powershell_script