skip to Main Content

I have an EXE program for file format conversion. The input file name sometimes contains Chinese or other characters, but I encountered some environment encoding issues during the docker deployment process. The program can run normally on Windows 10/11, where the language environment is zh-CN and the code page displayed by the chcp command is 936.

The docker environment uses the image mcr.microsoft.com/windows/servercore:ltsc2022, and the host environment is Windows 11 with the parameter –isolation=process. In the container, using Get-WinSystemLocale shows zh-CN, which is the same as the host. However, the chcp command still shows 437, so I think it’s a code page issue. I’m not sure if this is correct.

I tried to run it on a newly installed Windows 10 with English language, but it failed. After setting Control Panel -> Region -> Administrative Language for non-Unicode programs to Chinese Simplified, it works.

Update: During my test on @GChuf 2 solutions, i found this may not be chcp problem. After change chcp to 936 sucessfully in docker, if myprogram.exe take Chinese characters as input, it can’t output right content.

So, I simplified the problem a bit and wrote a helloworld test program. The program receives parameters that may contain Chinese characters and then prints out the parameters.

#include <iostream>

int main(int argc, char* argv[]) {
    std::cout << argv[1] << std::endl;
    return 0;
}

In Windows host, chcp:936, Get-WinSystemLocale:zh-CN

.helloworld.exe hello // hello
.helloworld.exe 你好  // 你好

In docker, chcp:936, Get-WinSystemLocale:zh-CN

.helloworld.exe hello // hello
.helloworld.exe 你好  // ??

2

Answers


  1. Chosen as BEST ANSWER

    I found the following two helpful reference links. According to what was said above, using the following command on my_program.exe worked.

    1. touch my_program.1.mainfest file
    <?xml version="1.0" encoding="utf-8"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        ...
        <asmv3:application>
            <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">
                <activeCodePage>Legacy</activeCodePage>
            </asmv3:windowsSettings>
        </asmv3:application>
        ...
    </assembly>
    
    1. In powershell, exec this command
    mt.exe -manifest my_program.1.manifest -outputresource:.my_program.exe;#1
    
    1. Copy my_program.exe to docker container, and it work well.

    Reference:

    1. Encoding inside container
    2. The activeCodePage manifest element can be used for more than just setting UTF-8 as the active code page
    3. code-page-identifiers
    4. Installing Language Packs for Windows in containers
    5. Publish Server Core image with da-DK culture

  2. I can think of 2 solutions to this problem:

    1. You can try to modify the global codepage setting when building your container – I’m not 100% sure where that setting is (it’s inside the registry – chcp does not change global settings).
      Take a look at this answer for setting codepage for console only.
      You could try to find out which key is modified when you change "Control Panel -> Region -> Administrative Language for non-Unicode" by monitoring the registry, or ocmparing 2 versions of registry.

    2. You can try to set chcp BEFORE you call your .exe file – because chcp only changes the codepage for the current session (if you open another cmd window, you will have to change the codepage again). In batch file, this would look like this: chcp 936 && C:your_program.exe $filepath (you would have to pass the filepath as an argument to your batch file, which slightly complicates things. Maybe you can do something similar without a batch file as well.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search