Version 8 of encoding system

Updated 2008-12-16 23:03:41 by rpremuz

encoding system ?encoding?

Set the system encoding to encoding. If encoding is omitted then the command returns the current system encoding. The system encoding is used whenever Tcl passes strings to system calls.


RS 2005-06-14: On Windows, a different encoding is used for consoles (cmd.exe). You can find out which with

 fconfigure stdout -encoding

which gives cp437 for KBK in New York and me in Germany. Reconfiguring stdout doesn't really work - even if you

 fconfigure stdout -encoding cp1252

the stubborn thing still stays with cp437...

MG does this on 2005-06-16, on Win XP in Britain. When I run the 'Command Prompt', cmd.exe, or tclsh.exe

 fconfigure stdout -encoding

begins as cp850, and trying to change it, then check it, with the same command seems to be successful. When I run Wish and check fconfigure stdout -encoding in the ('console show') console, it starts as utf-8, and is again changable. In all of the above, though, encoding system is cp1252.


Can soneone elaborate on the meaning of the 'identity' encoding? When using freewrap I get:

  % encoding system
  identity

What is this and what is it used for?

schlenk 2005-06-27: The identity encoding is for testing purposes, it should not be used without very good reasons. If you see your encoding system set to identity, you are missing the proper encoding files for your setup. This happens with tclkit-sh.exe on windows or other wrapped applications which do not include the right encodings for the local system they are running on.


rpremuz (2008-12-03) On MS Windows XP Pro. SP3 with Croatian regional settings I tested the following test.tcl on Tcl 8.5.5:

 puts stderr "System encoding: [encoding system]"
 puts stderr "Encoding of stdin: [fconfigure stdin -encoding]"
 puts stderr "Encoding of stdout: [fconfigure stdout -encoding]"

tclsh test.tcl

 System encoding: cp1250
 Encoding of stdin: unicode
 Encoding of stdout: unicode

dir | tclsh test.tcl

 System encoding: cp1250
 Encoding of stdin: cp1250
 Encoding of stdout: unicode

tclsh test.tcl | more

 System encoding: cp1250
 Encoding of stdin: unicode
 Encoding of stdout: cp1250

dir | tclsh test.tcl | more

 System encoding: cp1250
 Encoding of stdin: cp1250
 Encoding of stdout: cp1250

The results show that if stdin or stdout corresponds to a terminal, its default encoding is "unicode". Otherwise it is the system encoding.

On Unix platform the default encoding for stdin and stdout is always the locale-dependent system encoding.


See also:


Tcl syntax help - Category Command - Category Binary Data - Category Introspection