Skip to content

Commit

Permalink
Set console output code page to UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn committed Dec 25, 2020
1 parent 9328075 commit 7b23c94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/WinSW.Core/Native/ConsoleApis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal static class ConsoleApis
{
internal const int ATTACH_PARENT_PROCESS = -1;

internal const uint CP_UTF8 = 65001;

[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool AllocConsole();

Expand All @@ -23,6 +25,9 @@ internal static class ConsoleApis
[DllImport(Libraries.Kernel32)]
internal static extern bool SetConsoleCtrlHandler(ConsoleCtrlHandlerRoutine? handlerRoutine, bool add);

[DllImport(Libraries.Kernel32)]
internal static extern bool SetConsoleOutputCP(uint codePageID);

internal delegate bool ConsoleCtrlHandlerRoutine(CtrlEvents ctrlType);

internal enum CtrlEvents : uint
Expand Down
2 changes: 2 additions & 0 deletions src/WinSW/WrapperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ private Process StartProcess(string executable, string? arguments, LogHandler? l
Debug.Assert(succeeded);
succeeded = ConsoleApis.SetConsoleCtrlHandler(null, false); // inherited
Debug.Assert(succeeded);
succeeded = ConsoleApis.SetConsoleOutputCP(ConsoleApis.CP_UTF8);
Debug.Assert(succeeded);

Process process;
try
Expand Down

0 comments on commit 7b23c94

Please sign in to comment.