from a ruby script if i list the ENV hash i get (between others) :
__CF_USER_TEXT_ENCODING => 0x1F5:0:1
when the script is ran from a user and :
__CF_USER_TEXT_ENCODING => 0x0:0:1
when run via sudo.
however i have :
imyt% sudo cat /var/root/.CFUserTextEncoding
0:1%
imyt% cat ~/.CFUserTextEncoding
0:1%
pretty the same.
could that explain the fact that when running a script via sudo i do
have to force encoding ie :
File.open(MACSOUP_SIGNATURES_FILE,:encoding => “UTF-8”)
and no need for ":encoding => “UTF-8"” when running as user.
and notice that in both cases i do have :
LANG => fr_FR.UTF-8
501 % env | grep CF
__CF_USER_TEXT_ENCODING=0x1F8:0:0
502 % ls -l ~/.CF*
ls: /Users/ryan/.CF*: No such file or directory
I’m set for English env in System Prefs on OSX so I was a bit surprised
to see the env var.
“CF” is a prefix that stands for “Core Foundation”, aka the bottom layer
of cocoa… so you may want to fire up xcode’s lovely help system and
search around there.
=?ISO-8859-1?Q?Une_B=E9vue?= wrote in post #955862:
could that explain the fact that when running a script via sudo i do
have to force encoding ie :
File.open(MACSOUP_SIGNATURES_FILE,:encoding => “UTF-8”)
and no need for ":encoding => “UTF-8"” when running as user.
If you want the long answer to that question, see
The short answer is: (1) Ruby’s behaviour when dealing with strings read
from files is influenced by the contents of environment variables,
unless you explicitly tell it otherwise; and (2) sudo clears out
environment variables, unless you explicitly tell it otherwise.
and notice that in both cases i do have :
LANG => fr_FR.UTF-8
The rules for locale setting are complex, and there are other
environment variables such as LC_ALL which take precedence over it. See
‘man setlocale’