6

This is the program I am currently running with Perl 6 (Rakudo Star 2017.10 under Windows 7 x64, codepage chcp 65001)

use v6;
say chr(300) x 3, chr(301), 'UVW';

I expect to have exactly one line of output:

ĬĬĬĭUVW

but I get a mysterious second line of output ('VW'):

ĬĬĬĭUVW
VW

(By the way, when I redirect the output into a file, the problem goes away)

So my question is as follows, how can I make Perl 6 to output exactly one line ? -- (unfortunately, redirecting the output into a file is not an option for me)

Additional information: As can be seen in the old Stackoverflow question http://stackoverflow.com/questions/25585248 I had exactly the same problem with Perl 5. The solution in Perl 5 was to inject a command

binmode(STDOUT, ':unix:encoding(utf8):crlf');

So the question I have now is as follows:

What is the Perl 6 equivalent of the Perl 5 command binmode(STDOUT, ':unix:encoding(utf8):crlf') ?

Thanks in advance for your help.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
user2288349
  • 267
  • 2
  • 12
  • As I understand it, the command in Perl 5 (binmode(STDOUT, ':unix:encoding(utf8):crlf');) is considered a workaround for a bug, see https://stackoverflow.com/questions/23416075. – user2288349 Dec 30 '17 at 16:24
  • 2
    Pointer for readers: you must run `chcp 65001` on the command line before running the Perl 6 code. – Christopher Bottoms Dec 30 '17 at 18:01
  • I'm using Rakudo-Star 2017.10 on Windows 10 and am not having any problems with this code. – Christopher Bottoms Dec 30 '17 at 18:02
  • 1
    I don't see the same issue outside of Windows. – brian d foy Dec 30 '17 at 18:06
  • Can you tell us more about which program is providing your command prompt and how you've set it up? – brian d foy Dec 30 '17 at 18:07
  • 3
    Couldn't repro on 2017.12-42-g1ea0c90 on Win10. Neither with nor without chcp 6500, neither on command line nor with a script-a-in-file. Tried on WSL bash too; no issue there. –  Dec 30 '17 at 18:08
  • I don't have Windows 10 handy right now, but it seems that the problem is resolved in Windows 10. Unfortunately I am stuck with Windows 7 :( – user2288349 Dec 31 '17 at 12:35
  • To save folk time, make sure you've read [this perlbug comment](https://rt.perl.org/Public/Bug/Display.html?id=121783#txn-1294240). – raiph Dec 31 '17 at 14:58
  • 3
    To save time for anyone considering a p6 patch to hide microsoft's bug, see [the corresponding python bug and its resolution](http://bugs.python.org/issue1602), plus @sinan-Ünür's note in the p5 bug report I just linked about "WriteFile using synchronous IO" and that "Therefore, the right thing to do seems to be to always return count from PerlIOWin32_write if WriteFile succeeds regardless of the value of len", and Tony Cook's (p5) patch which seems to do exactly that with the comment "So we assume that if anything was written that the entire buffer was written correctly.". – raiph Dec 31 '17 at 15:23

0 Answers0