[fpc-devel] Console encoding on Windows, output to file with ">"

Ondrej Pokorny lazarus at kluug.net
Wed May 3 08:34:14 CEST 2017


Hello,

I have a simple FPC program:

---
program GermanTest;

{$codepage utf8}
begin
   Writeln('ÄäÖöÜüß');
end.
---

If I run it in the console, I see correct characters:

BUT when I redirect the output to a file with ">" :

GermanTest.exe > GermanTest.txt I get corrupted characters "Ž„™”šá" 
(see attachment).

I tried various possibilities but either the console output is correct 
or the file output is correct. Never both of them.

E.g.
---
program GermanTest;

{$codepage utf8}

uses
   Windows, SysUtils, Classes;

begin
   SetConsoleOutputCP(CP_UTF8);

   Writeln('ÄäÖöÜüß');
end.
---

Works fine for file output but the console shows wrong characters.

What should I do so that both outputs are correct? Or is it an FPC bug? 
Delphi works fine - both outputs are correct.

FPC version: current trunk 3.1.1 Windows, 32bit.
OS: Windows 10, 64bit

Ondrej

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170503/ce35a608/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nnafhnnfamjephpe.png
Type: image/png
Size: 3351 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170503/ce35a608/attachment.png>
-------------- next part --------------
??????????????


More information about the fpc-devel mailing list