Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-07

How to write text to the console?

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Hope I got your attention with the subject ;)

After having had help on the list I managed to write UTF8 text to the Windows Vista console using 2.6
However, my test program (see attachment) fails on trunk.

See
http://lazarus.freepascal.org/index.php/topic,17548 for discussion (initially about other problem)
Also had a look at

This works in FPC 2.7.1:
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),@s[1],length(s),bw,nil); ... but seems to be Windows-only.

What am I missing and what is the easiest cross-platform way to output/accept UTF8 text to/from the console?

Should I set the console codepage back to the one in use before the program ran? Should I also mess with SetConsoleCP and/or SetTextCodePage?

Thanks,
Reinier

Reply by email

Unknown author
to Reinier Olislagers
Reinier Olislagers wrote 15 lines
Hope I got your attention with the subject ;) After having had help on the list I managed to write UTF8 text to the Windows Vista console using 2.6 However, my test program (see attachment) fails on trunk. See http://lazarus.freepascal.org/index.php/topic,17548 for discussion (initially about other problem) Also had a look at This works in FPC 2.7.1: WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),@s[1],length(s),bw,nil); ... but seems to be Windows-only.

Indeed.

What am I missing and what is the easiest cross-platform way to output/accept UTF8 text to/from the console?

There is no cross-platform way.

On Unix, the (x/k)console is usually UTF-8 these days, so you don't need to do anything. You need to look at the various localization environment variables.

Should I set the console codepage back to the one in use before the program ran? Should I also mess with SetConsoleCP and/or SetTextCodePage?

These don't exist on non-windows ?

Michael.

Reply by email

Reinier Olislagers
to Unknown author
Show quoted text 21 lines
On Mon, 16 Jul 2012, Reinier Olislagers wrote: > This works in FPC 2.7.1: > WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),@s[1],length(s),bw,nil); > ... but seems to be Windows-only. Indeed. > > What am I missing and what is the easiest cross-platform way to > output/accept UTF8 text to/from the console? There is no cross-platform way. On Unix, the (x/k)console is usually UTF-8 these days, so you don't need to do anything. You need to look at the various localization environment variables. > Should I set the console codepage back to the one in use before the > program ran? Should I also mess with SetConsoleCP and/or SetTextCodePage? These don't exist on non-windows ?

I have no idea, haven't looked yet. I was more or less looking at anything that might have to do with code pages and plugging things into the code.
Rather than trying to experiment further, I thought I'd ask.

Reply by email

Reinier Olislagers
to Unknown author: Indeed. There is no cross-platform way. On Unix, the (x/k)console is usually UTF-8 these…
On Mon, 16 Jul 2012, Reinier Olislagers wrote: > After having had help on the list I managed to write UTF8 text to the > Windows Vista console using 2.6 > However, my test program (see attachment) fails on trunk.

<snip>

Show quoted text 5 lines
> This works in FPC 2.7.1: > WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),@s[1],length(s),bw,nil); > ... but seems to be Windows-only. Indeed.

Thanks Michael, I forgot: do you or does anybody know why the example code I posted works in FPC 2.6.1 and doesn't work in FPC 2.7.1?

Reply by email