How to do proper Unicode and ANSI output redirection on cmd.exe?

后端 未结 2 1924
执笔经年
执笔经年 2020-12-09 12:52

If you are doing automation on windows and you are redirecting the output of different commands (internal cmd.exe or external, you\'ll discover that your log fi

相关标签:
2条回答
  • 2020-12-09 13:13

    You can use chcp to change the active code page. This will be used for redirecting text as well:

    chcp 65001
    

    Keep in mind, though, that this will have no effect if cmd was started with the /u switch which forces Unicode (UTF-16 in this case) redirection output. If that switch is active then all output will be in UTF-16LE, regardless of the codepage set with chcp.

    Also note that the console will be unusable for interactive output when set to Raster Fonts. I'm getting fun error messages in that case:

    C:\Users\Johannes Rössel\Documents>x
    Active code page: 65001
    
    The system cannot write to the specified device.
    

    So either use a sane setup (TrueType font for the console) or don't pull this stunt when using the console interactively and having a path that contains non-ASCII characters.

    0 讨论(0)
  • 2020-12-09 13:29
    binmode(STDOUT, ":unix");
    

    without

    use encoding 'utf8';
    

    Helped me. With that i had wide character in print warning.

    0 讨论(0)
提交回复
热议问题