Get or 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 (as in open) or retrieves them from system calls (as in glob). It is also the default encoding for newly created channels.
The system encoding is a process-global resource: It is shared among all interpreters in the current process, and can be changed by any of them.
You should not normally have to set the system encoding; if Tcl is getting its initial guess wrong, this is a bug and will impact on most 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.
PYK 2018-12-04: It is so because your Tcl configuration is borked.
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]"
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.
DKF: Windows has a special API for talking to the terminal, so if we detect it we use that directly. That API has a Unicode variant. (In fact, on Windows the system encoding is really the encoding of calls into the ...A API, whereas we mostly use the ...W API directly. Which is the Right Thing really.)