Windows: environment is not reflected properly (special characters)
If you want to try this in cmd.exe, be sure to set the cmd.exe font to "Lucida Console". I don't have the hungarian locale, so the locale is set to US. I ran a [glob -directory C:/Users *] and the proper value is returned. C:\Users\Gergő\Desktop\BallroomDJ>.\windows\64\tcl\bin\tclsh.exe % puts $::env(USERPROFILE) C:\Users\Gergo % exit C:\Users\Gergő\Desktop\BallroomDJ>echo %USERPROFILE% C:\Users\Gergő C:\Users\Gergő\Desktop\BallroomDJ>
dcf2c77048env.test: added test for windows illustrating bug [8f89e2e059] - loss of multi-byte chars in environment if single-byte system encoding used check-in2020-03-13 13:06:53
I tried chcp 1250 and no better.
Note that 'Gergő' is using some windows code page, not utf-8. So there are all sorts of problems using windows account names with special characters, as you can very easily get mixed encodings within path names.
The code page of console does no matter, neither for supplying environment parameters nor for the substitution of them. Currently tcl uses a system encoding to convert environment to utf-8. So (unless it is fixed) you can set it to something better matching your locale (I guess cp1252)... I believe cp437 is not really suitable for Hungarian locale.
Note that in example below I changed console CP (to utf-8) only in order to see proper output for different encodings (it does not affect the system encoding).
As you can see the value gets changed related to the system encoding currently used.
> chcp 65001
> set TEST=--äöüß-- && tclsh86
% puts [encoding system]\t$env(TEST)
cp1252 --äöüß--
% encoding system cp437
% puts [encoding system]\t$env(TEST)
cp437 --Σ÷ⁿ▀--
% encoding system cp1251
% puts [encoding system]\t$env(TEST)
cp1251 --дцьЯ--
This behavior can (and I guess, must) be changed since Windows has a wide-char functions to obtain environment...
I have already fixed that in my own fork and would take a look whether it can be back-ported without compat issues.
Even with the correct system encoding set on the command line, the environment isn't picked up properly. I hope your fixes can be applied. I don't expect that special characters in the account name will ever work well due to mixed encodings in the path name, but having environment variables that are not valid at all is definitely wrong. C:\Users\Gregő\Desktop\BallroomDJ>.\windows\64\tcl\bin\tclsh.exe -encoding cp1250 % puts $::env(USERPROFILE) C:\Users\Grego % puts [file exists $::env(USERPROFILE)] 0 %
1. You cannot change the system encoding via command line parameter - this specifies only the char-set of the content of given script (so basically loads the file with proper encoding only):
# this does not change system encoding: > echo puts [encoding system] | tclsh86 -encoding utf-8 cp1252 # this will load "main.tcl" using utf-8, but also does not change sys-encoding: > echo puts [encoding system] > %TEMP%\main.tcl > tclsh86.exe -encoding utf-8 %TEMP%\main.tcl && del %TEMP%\main.tcl cp1252So you have either to set it properly in the system or in the main script self.
2. I tried to back-port my "fix" and got many conflicts I have still to resolve (and I'm pretty sure I get some things in env.test that I have to correct too)... be patient.
Fix is provided in branch [bug-8f89e2e059] (tested for windows only with make-build)
Tested now on Visual Studio too. Made some additional fixes. I think it's good to be merged to 8.6. Thanks!
Ok, let us see what Travis will say about the branch :)
Merged, thus close. Thx, Jan!