Windows UTF-8 printed with chcp 65001 - characters mysteriously duplicated

Here is one thing I can’t look back at:

I am using Windows 7 and Strawberry Perl 5.20 and I want to write UTF-8 on the console (cmd.exe) using chcp 65001.

UTF-8 characters come out fine, even> 255, but there is a mysterious duplication of some characters (this only happens if I don't get redirected to a file)

EDIT: Now I saw another publication that was essentially the same problem in last-octet-repeated-when-my-perl-program-outputs-a-utf-8 - the solution is to enter binmode (STDOUT, 'unix: encoding (utf8): crlf') to the perl program - I tested and now works fine

Thanks to everyone who looked into this strange problem.

In a nutshell, I write the line UTF-8 (chr (300) x 3) .chr (301). "UVW \ x {0D} \ x {0A}" when I get redirected to a flat file and then print the flat file, everything is fine.

However, when I type directly on the console, some characters are mysteriously duplicated (I'm talking about "VW" characters on a separate line), and I don't know why

Here is my test output

Page de codes active : 65001

Redirected into a file:
-----------------------
ĬĬĬĭUVW

Printed directly:
-----------------
ĬĬĬĭUVW
VW

IO-Layers = (unix crlf)

C4ACC4ACC4ACC4AD5556570D0A

Here is my test program:

@echo off
chcp 65001
echo.

set H1=BEGIN{binmode(*STDIN); undef $/;
set HEXDUMP="%H1% print uc(unpack('H*',<STDIN>)), qq{\n}}"

set L1=my @l = PerlIO::get_layers(*STDOUT, output, 1);
set LAYERS="%L1% print {*STDERR} qq{IO-Layers = (@l)\n};"

set PROG="print chr(300) x 3, chr(301), qq{UVW\n};";

set TFILE=%TEMP%\tfile.txt

echo Redirected into a file:
echo -----------------------
perl -C6 -e%PROG% >%TFILE% && type %TFILE%
echo.

echo Printed directly:
echo -----------------
perl -C6 -e%PROG%

echo.
perl -e%LAYERS%
echo.

perl -e%HEXDUMP% <%TFILE%

echo.
pause

As I said, the characters themselves print correctly, but why is there mysterious duplication? ... and why * only * if not redirected to a file?

+2
source share
1 answer

As I suspected, this was reported as a crash in Windows software:

​​Windows. , 65001, WriteFile() .

, :unix:encoding(utf8):crlf PerlIO, , , .

+3

Source: https://habr.com/ru/post/1691550/


All Articles