我这里有一个程序,这取决于netstat
. 更具体的:netstat -apn
。
下面是一个正常输出的例子。
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
Run Code Online (Sandbox Code Playgroud)
我的一个客户有一些其他输出(例如):
Proto Recv-Q Send-Q Endereço Local Endereço Remoto Estado PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* OUÇA -
Run Code Online (Sandbox Code Playgroud)
我想使用更改后的输出来测试我的软件netstat
,例如客户端的输出。
所以问题是:我应该怎么做才能改变 的输出语言netstat
,这样我才能重现错误,客户端得到?
我已经尝试用 更改语言export LANG=pt_PT
,但输出没有改变。
首先,您需要确保您的机器设置了必要的语言环境。您可以使用locale -a
. 例如,在我的系统上:
$ locale -a
C
C.UTF-8
el_GR.utf8
en_US.utf8
fr_FR.utf8
POSIX
Run Code Online (Sandbox Code Playgroud)
正如您在上面看到的,我没有葡萄牙语语言环境。在我的 Debian 上,我可以通过运行sudo dpkg-reconfigure locales
并选择相关语言环境来创建它:
套餐配置
???????????????????????????? Configuring locales ????????????????????????????
? Locales are a framework to switch between multiple languages and allow ?
? users to use their language, country, characters, collation order, etc. ?
? ?
? Please choose which locales to generate. UTF-8 locales should be chosen ?
? by default, particularly for new installations. Other character sets may ?
? be useful for backwards compatibility with older systems and software. ?
? ?
? Locales to be generated: ?
? ?
? [ ] pt_BR.UTF-8 UTF-8 ? ?
? [ ] pt_PT ISO-8859-1 ? ?
? [*] pt_PT.UTF-8 UTF-8 ? ?
? [ ] pt_PT@euro ISO-8859-15 ? ?
? [ ] quz_PE UTF-8 ? ?
? ?
? ?
? <Ok> <Cancel> ?
? ?
?????????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
点击 后Enter,你应该得到:
$ sudo dpkg-reconfigure locales
Generating locales (this might take a while)...
el_GR.UTF-8... done
en_US.UTF-8... done
fr_FR.UTF-8... done
pt_PT.UTF-8... done
Generation complete.
Run Code Online (Sandbox Code Playgroud)
如果您使用的不是基于 Debian 的发行版,则需要手动执行此操作:
将相关的语言环境名称添加到/etc/locale.gen
. 例如:
pt_PT.UTF-8 UTF-8
Run Code Online (Sandbox Code Playgroud)跑 locale-gen
经过上述步骤(手动方法或方法dpkg-reconfigre locales
),locale -a
还将列出葡萄牙语语言环境:
$ locale -a
C
C.UTF-8
el_GR.utf8
en_US.utf8
fr_FR.utf8
POSIX
pt_PT.utf8
Run Code Online (Sandbox Code Playgroud)
现在,您可以选择显示的语言输出:
$ LC_ALL=el_GR.utf8 date
??? 14 ??? 2015 12:34:28 ?? EEST
$ LC_ALL=fr_FR.utf8 date
mercredi 14 octobre 2015, 12:35:07 (UTC+0300)
$ LC_ALL=pt_PT.utf8 date
Qua Out 14 12:35:11 EEST 2015
Run Code Online (Sandbox Code Playgroud)
但是,特定程序是否能够在所选语言环境中打印输出将取决于它是否已被翻译;关于软件包是否附带相关.mo
翻译文件。在 的情况下netstat
,这是/usr/share/locale/${LANG%_*}/LC_MESSAGES/net-tools.mo
。在我的 Debian 上,法语语言环境有,但葡萄牙语语言环境没有:
$ ls /usr/share/locale/{fr,pt}/LC_MESSAGES/net*
ls: cannot access /usr/share/locale/pt/LC_MESSAGES/net*: No such file or directory
/usr/share/locale/fr/LC_MESSAGES/net-tools.mo
Run Code Online (Sandbox Code Playgroud)
这就是我可以netstat
用法语跑步的原因:
$ LC_ALL=fr_FR.utf8 netstat -apn | head -n2
(Tous les processus ne peuvent être identifiés, les infos sur les processus
non possédés ne seront pas affichées, vous devez être root pour les voir toutes.)
Connexions Internet actives (serveurs et établies)
Proto Recv-Q Send-Q Adresse locale Adresse distante Etat PID/Program name
Run Code Online (Sandbox Code Playgroud)
但不是葡萄牙语:
$ LC_ALL=pt_PT.utf8 netstat -apn | head -n2
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
735 次 |
最近记录: |