LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-27-2012, 04:41 AM   #1
Himilhil
Member
 
Registered: Jun 2009
Posts: 52

Rep: Reputation: 15
How to switch charset in terminal?


I have to execute with a sqlplus sql scripts written using CP1251 charset. For this purpose i assigned "RUSSIAN_RUSSIA.CL8MSWIN1251" to NLS_LANG environment variable. At the same time a terminal i execute scripts on is configured to use UTF-8 charset by default. Problem is that the sqlplus outputs messages in CP1251 and they are unreadable on the terminal. I tried to assign ru_RU.CP1251 to LANG environment variable. It didn't help. Is there a short way to switch charset in one virtual terminal and then switch it back?
 
Old 01-27-2012, 06:07 AM   #2
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

did you try this ?
Maybe it will work

good luck
 
Old 01-27-2012, 06:58 AM   #3
Himilhil
Member
 
Registered: Jun 2009
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by lithos View Post
Hi,

did you try this ?
Maybe it will work

good luck
Yes, i did. It doesn't work:
Code:
$ echo $LANG
ru_RU.utf8
$ echo $LC_ALL

$ enconv -x cp1251 test.sql
$ export LANG=ru_RU.cp1251
$ export LC_ALL=$LANG
$ cat test.sql
�����
 
Old 01-27-2012, 11:41 AM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
I noticed you are using some mysql query and as it happened to me that some CP-8859-2 characters in database were not displayed I had to use:
Code:
mysql charset connection
Posted by Charly R on March 29 2007 12:24am
I've spent quite a lot of time trying to make MySQL 4.1 and PHP working with my tables in cp1251 charset.

Adding on my local PC the following line to the my.ini solved the problem but unfortunately I can't do the same on my hosting provider space
default-character-set=cp1251

So after trying quite a lot of combinations finally I've found that I need to add only one query set just after connecting to the database in my php script
mysql_query ('SET NAMES CP1251');
It's worth reading it though it can solve the problem with mysql character sets displaying unknown characters.


good luck
 
Old 01-27-2012, 04:12 PM   #5
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
if you are using Bash, then set
Code:
export LANG="ru_RU.CP1251" LC_ALL="ru_RU.CP1251"
to set the locale to Russian using cp1251 charset.

You can always run a single command using
Code:
command | iconv -f cp1251//TRANSLIT
to display the output of the command correctly in your terminal, regardless of whatever charset your terminal uses, if the command output is in cp1251. (The //TRANSLIT tells iconv to use nearest equivalents if the exact characters cannot be displayed.)

If you have a curses program -- a text-based interactive program -- which uses some other character set than your terminal is set to, you can use luit :
Code:
luit -encoding cp1251 -- command
to run it. Very good for old text-based games, I hear.

I like to keep my terminal in UTF-8, but connect to an ancient machine which uses ISO-8859-15. A simple luit -encoding iso-8859-15 ssh ancient.machine works perfectly. If interrupted/killed, luit may forget to restore the terminal settings, but that is harmless: just run stty sane or tput reset to fix. The former will not clear the terminal, but may not work; the latter will clear your scrollback. Both are completely safe to run.
 
Old 02-08-2012, 05:55 AM   #6
Himilhil
Member
 
Registered: Jun 2009
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Nominal Animal View Post
if you are using Bash, then set
Code:
export LANG="ru_RU.CP1251" LC_ALL="ru_RU.CP1251"
to set the locale to Russian using cp1251 charset.
Apparently it doesn't work. Bash still uses utf8 encoding while handling output of sqlplus after I've changed LANG and LC_ALL. When sqlplus prints out with cp1251 russian characters in it's output looks still unreadable.
Quote:
Originally Posted by Nominal Animal View Post
You can always run a single command using
Code:
command | iconv -f cp1251//TRANSLIT
to display the output of the command correctly in your terminal, regardless of whatever charset your terminal uses, if the command output is in cp1251. (The //TRANSLIT tells iconv to use nearest equivalents if the exact characters cannot be displayed.)
Unfortunatelly it's not an appropriate way for me. I need to work with sqlplus interactively.
Quote:
Originally Posted by Nominal Animal View Post
If you have a curses program -- a text-based interactive program -- which uses some other character set than your terminal is set to, you can use luit :
Code:
luit -encoding cp1251 -- command
to run it. Very good for old text-based games, I hear.

I like to keep my terminal in UTF-8, but connect to an ancient machine which uses ISO-8859-15. A simple luit -encoding iso-8859-15 ssh ancient.machine works perfectly. If interrupted/killed, luit may forget to restore the terminal settings, but that is harmless: just run stty sane or tput reset to fix. The former will not clear the terminal, but may not work; the latter will clear your scrollback. Both are completely safe to run.
It works in some strange way. Without luit russian characters look in sqlplus' output like question marks within hexagons. With luit they look like a jumble of various letters, digits and other characters.
 
Old 03-14-2012, 04:49 PM   #7
Himilhil
Member
 
Registered: Jun 2009
Posts: 52

Original Poster
Rep: Reputation: 15
I've tried to run less with luit for example:
Code:
luit -encoding cp1251 less test.txt
That's what i saw in less:
Code:
j`j`ÿ-rn jhphkkhweqj`ÿ m`dohq|
Definitely it wasn't a cp1251 encoded text which is in this file. Here is my locale settings:
Code:
$ locale
LANG=ru_RU.utf8
LC_CTYPE="ru_RU.utf8"
LC_NUMERIC="ru_RU.utf8"
LC_TIME="ru_RU.utf8"
LC_COLLATE="ru_RU.utf8"
LC_MONETARY="ru_RU.utf8"
LC_MESSAGES="ru_RU.utf8"
LC_PAPER="ru_RU.utf8"
LC_NAME="ru_RU.utf8"
LC_ADDRESS="ru_RU.utf8"
LC_TELEPHONE="ru_RU.utf8"
LC_MEASUREMENT="ru_RU.utf8"
LC_IDENTIFICATION="ru_RU.utf8"
LC_ALL=
I've also checked if i have a proper locale to display a cp1251 encoded text:
Code:
$ locale -a | egrep '.*ru.*1251.*'
ru_RU.cp1251
If i try to convert content of this file with iconv -f CP1251 i have a correct cyrillic text on screen. What do I wrong?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
could not switch to terminal session alpha_lin Ubuntu 2 10-06-2006 07:00 AM
gnome-terminal wrong charset (ANSI_X3.4-1986 not ISO-8859-1). omes Linux - General 1 06-10-2005 09:55 PM
is there a script that controls what happens when you switch a terminal? Fascistchicken Linux - General 2 09-29-2004 10:11 PM
Keyboard layout and terminal charset... [MDK9.1] lucat Linux - Distributions 0 03-31-2003 02:30 PM
Keyboard layout and terminal charset... lucat Linux - Hardware 0 03-31-2003 02:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration