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

Michael Van Canneyt michael at freepascal.org
Wed May 3 18:36:33 CEST 2017



On Wed, 3 May 2017, Ondrej Pokorny wrote:

> Michael, because I cannot comment on a closed issue report I post my 
> answer to https://bugs.freepascal.org/view.php?id=31746#c100091 here:
>
> > I don't think what you write is correct. As far as I can see in the 
> code of Delphi Berlin: Delphi uses always the defaultsystemcodepage for 
> text files, regardless of what the file is used for.
>
> What do you mean? I checked both Berlin and Tokyo and in "function 
> TextOpen(var t: TTextRec): Integer;" in unit System you see that if the 
> text file is used for console input/output the CodePage is 
> GetConsoleOutputCP/GetConsoleCP whereas if the text file is used for 
> other purposes it uses DefaultSystemCodePage. (Search for "if 
> GetFileType(t.Handle) = 2 then"; 2=FILE_TYPE_CHAR).

Hmh. 
I looked in a different function and missed this.  You are right.

I don't think this is very good behaviour.

IMHO the output should be the same regardless of whether the output is piped or not.

I can understand a check for stdinputhandle/stdoutputhandle.
(specially on windows with the weird handling of a console)

But whether or not the output is piped: the program should handle both cases equally.

I have reopened the bugreport. Some windows user should check this.

Michael.



More information about the fpc-devel mailing list