mac 连接 centos 服务器时报警告: -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file
解决 Bash 警告:setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)在使用 Linux 系统时,有时会遇到一个常见的警告信息:bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)这个警告通常出现在系统尝试设置特定的区域设置(locale)但失败的情况下 通过上述步骤,您应该能够解决 bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8) 这个警告。 /test_locale.sh可能的输出如果系统没有正确安装或配置 en_US.UTF-8 语言环境,你可能会看到类似以下的输出:bash: warning: setlocale: LC_CTYPE setlocale: LC_CTYPE::setlocale 是一个 C 库函数,用于设置或获取当前程序的区域设置(locale)。
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory vi /etc/
函数 char* setlocale (int category, const char* locale); setlocale 函数用于修改当前地区,可以针对⼀个类项修改,也可以针对所有类项。 setlocale 的第⼀个参数可以是前面说明的类项中的⼀个,那么每次只会影响⼀个类项,如果第⼀个参数是LC_ALL,就会影响所有的类项。 C标准给第⼆个参数仅定义了2种可能取值:“C"和”"。 在任意程序执行开始,都会隐藏式执行调用: setlocale(LC_ALL, "C"); 当地区设置为"C"时,库函数按正常方式执行,小数点是一个点。 当程序运行起来后想改变地区,就只能显示调用setlocale函数。用" "作为第2个参数,调用setlocale函数就可以切换到本地模式,这种模式下程序会适应本地环境。 = setlocale(LC_ALL, NULL);//返回值是一个字符串指针,表示已经设置好的格式。
使用ssh远程登陆 IDC机房服务器,发现老是出现如下告警信息: -bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF -8): No such file or directory -bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF -8): No such file or directory -bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF -8): No such file or directory -bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF -8): No such file or directory -bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8)
str[len - i - 1] = temp; } return true; } bool ReverseString(char* str) { const char* local = setlocale (LC_ALL, NULL);//返回当前本地化,setlocale(LC_ALL,"")才是使用默认本地化 char* setlocal = setlocale(LC_ALL, "chs"); wcstombs(NULL, buf, NULL); change = wcstombs(str, buf, change + 1); delete []buf; setlocal = setlocale (LC_ALL, ""); return true; } ERROR: delete[]buf; setlocal = setlocale(LC_ALL, ""); return false
一、惊魂 0.1 秒凌晨 00:05,咖啡还没咽下去,SSH 刚连上开发机,终端啪地甩出一行:warning: setlocale: LC_CTYPE: cannot change locale (UTF 按上面第 ② 招 localedef 一把,再跑一遍,立刻多出来:en_US.utf8六、复盘小结(拿去贴 Wiki)现象:SSH 一登录就蹦 setlocale: LC_CTYPE: cannot change 我抿一口冷掉的咖啡——“warning: setlocale” 不是错,它只是 Linux 在深夜向你问好。按上面任意一招,把 locale 安顿好,下次 SSH 登录,让服务器学会沉默。
include “windows.h” using namespace std; //string 与 wstring之间的转换 string ws2s(const wstring &ws) { //setlocale 需要头文件#include “locale.h” string curLocale = setlocale(LC_ALL, NULL); setlocale(LC_ALL, “chs”); const len = 0; wcstombs_s(&len, _Dest, _Dsize, _Source, _TRUNCATE); string result = _Dest; delete[] _Dest; setlocale (LC_ALL, curLocale.c_str()); return result; } wstring s2ws(const string &s) { string curLocale = setlocale (LC_ALL, NULL); setlocale(LC_ALL, “chs”); const char* _Source = s.c_str(); size_t _Dsize = s.size() +
sys.exit(main()) File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main locale.setlocale (locale.LC_ALL, '') File "/usr/lib/python3.5/locale.py", line 594, in setlocale return _setlocale(category
本身就支持,我修改的时候,竟然改错了,结果重新登录及报了一大堆的错误,如下: [ora11g@rac1 caipiao]$ su - ora11g Password: -bash: warning: setlocale : LC_CTYPE: cannot change locale (zn_CN.UTF-8): No such file or directory -bash: warning: setlocale : LC_COLLATE: cannot change locale (zn_CN.UTF-8): No such file or directory -bash: warning: setlocale : LC_MESSAGES: cannot change locale (zn_CN.UTF-8): No such file or directory -bash: warning: setlocale : LC_NUMERIC: cannot change locale (zn_CN.UTF-8): No such file or directory -bash: warning: setlocale
微软开发文档对类项的介绍 1. 3 setlocale函数 char*setlocale(int category,const char* locale); setlocale 函数用于修改当前地区,可以针对一个类项修改 setlocale 的第一个参数可以是前面说明的类项中的一个,那么每次只会影响一个类项, 如果第一个参数是LC_ALL,就会影响所有的类项。 当程序运行起来后如果想改变地区,就需要调用setlocale函数。用""作为第2个参数,调用setlocale函数就可以切换到本地模式,这种模式下程序会适应本地环境。 setlocale(LC_ALL,"");//切换到本地环境 setlocale 的返回值是一个字符串指针,表示已经设置好的格式。如果调用失败,则返回空指针NULL 。 setlocale也可以用来查询当前地区,第二个参数设为NULL就可以了。
利用标准库函数可以完成char*与wchar_t*之间的转换,关键函数有setlocale()、wcstombs_s()和mbstowcs_s()。 2.1关键函数简介 (1)setlocale() 功能:配置地域化信息 头文件:< locale.h> 函数原型:char* setlocale(int category, const char* locale (LC_ALL, NULL); //curLocale="C" setlocale(LC_ALL, "chs"); const wchar_t* wcs = ws.c_str() (LC_ALL,NULL); //curLocale="C" setlocale(LC_ALL,"chs"); const char* source = s.c_str(); 在程序中去除相关的setlocale()函数调用,就得不到正确的结果。locale实际的作用是告诉操作系统,多字节字符串采用的是何种编码,“chs”表示简体中文。
#include <iostream> #include <locale> //setlocale函数在locale头文件中定义 using namespace std; int main () { //使用setlocale函数将本机的语言设置为中文简体 //LC_ALL表示设置所有的选项(包括金融货币、小数点,时间日期格式、语言字符串的使用习惯等),chs表示中文简体 setlocale(LC_ALL, "chs"); wchar_t wt[] = L"中国伟大复兴梦"; //大写字母L告诉编译器为"中"字分配两个字节的空间 wcout
/usr/bin/env python # -*- coding:utf-8 -*- import pysvn import locale import datetime import os def setlocale None: encoding = 'UTF-8' if encoding.lower == 'utf': encoding = 'UTF-8' locale.setlocale _": path = u"D:\\dsa\\测试" url = "http://192.168.5.110:808/svn/test/%E6%B5%8B%E8%AF%95" #setlocale
sMsg, sFunc + "Tmp", sSelf); return sMsg; } 2.3文件读写操作 int fileTest() { char* old_locale = _strdup(setlocale (LC_CTYPE, NULL)); setlocale(LC_CTYPE, "chs"); CString StrFileName("d:\\fileTest.lua"); CStdioFile CFile::Remove(StrFileName); CFile::Rename(StrTempFileName, StrFileName); printf("successful "); setlocale ); sMsg = regexSelfChangePos(sOut); return sMsg; } int fileTest() { char* old_locale = _strdup(setlocale (LC_CTYPE, NULL)); setlocale(LC_CTYPE, "chs"); CString StrFileName("d:\\fileTest.lua"); CStdioFile
函数 char* setlocale (int category, const char* locale); setlocale 函数用于修改当前地区,可以针对一个类项修改,也可以针对所有类项。 setlocale 的第一个参数可以是前面说明的类项中的一个,那么每次只会影响一个类项,如果第一个参数是LC_ALL,就会影响所有的类项。 当程序运行起来后想改变地区,就只能显示调用setlocale函数。用" "作为第2个参数,调用setlocale函数就可以切换到本地模式,这种模式下程序会适应本地环境。 setlocale(LC_ALL, " ");//切换到本地环境 setlocale的返回孩子是一个字符串指针,表示已经设置好的格式。如果调试失败,则返回空指针NULL。 setlocale()可以用来查询当前地区,这时第二个参数设为NULL就可以了 #include<locale.h> int main() { char* loc; loc = setlocale(
sys.exit(main()) File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main locale.setlocale (locale.LC_ALL, '') File "/usr/lib/python3.5/locale.py", line 594, in setlocale return _setlocale(category
sudo apt-get install language-pack-zh-hans-base sudo dpkg-reconfigure locales 使用 import locale locale.setlocale lambda x, y: cmp(x.course_name, y.course_name)) 测试用例 输入 # -*- coding: utf-8 -*- import locale locale.setlocale
解决方法, 程序里加 setlocale(LC_ALL, 'zh_CN'); setlocale(LC_ALL, 'zh_CN'); $objExcelReader = PHPExcel_IOFactory
: LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: : LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: : LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: : LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: : LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: