1

I have a problem when executing a "type" command on a file that containg regional characters. Although i can see the file properly with notepad or any other editor, when i try the command "type file" from the command line the regional characters are shown incorrectly.

I've tried executing chcp 850 or chcp 1250 but doesn't work. Executing cmd.exe /u doesn't work either.

Can u help me please? Thanks

4

Code page

You should set the code page used in the `chcp' command should match the encoding used in the file.

If Notepad recognises the file, it must be in one of the encodings that Notepad recognises:

  • ANSI ................. Usually Windows Latin-1, code page 1252.
  • Unicode .............. UTF-16 Little Endian with Byte Order Mark (BOM).
  • Unicode Big-endian ... UTF-16 big-endian with BOM.
  • UTF-8................. UTF-8 with BOM.

So, if the file was encoded in UTF-8 Unicode, you could use chcp 65001

As barlop commented below: "UTF-16 code pages are not supported in Command Prompt windows." Therefore in order to display data from UTF-16 files, the best you can do is probably to convert such files to UTF-8 using either Notepad or another suitable tool (perhaps iconv or recode).

Font

You should also set the font of the Command Prompt window to a font containing the particular characters you need to display. For example Lucida Console, if appropriate. You can do this from the context menu (right mouse button click) on the title-bar of the window, select the "Properties" option.

If you have a monospaced font whose character set includes the specific characters you need, you can adapt these instructions to make the command prompt window use that font.

Example

enter image description here

enter image description here

See also

See related question https://stackoverflow.com/questions/4572393/perl-unicode-glitch

  • I just tried copy/pasting from charmap into the command prompt, and with lucida console, and chcp 65001 and I just got squares for example for U+018F ƏƏ. Have you tried what you're suggesting? – barlop Mar 12 '11 at 2:46
  • @barlop: Yes I have tried what I suggested! Luisclin didn't say which particular characters his file contained, my answer said "a font containing the particular characters you need to display" evidently your Lucida Console font doesn't contain ƏƏ, choose or obtain an appropriate font as I suggested. – RedGrittyBrick Mar 12 '11 at 9:16
  • +1 excellent answer. I would add, looking at some codepages, trying UTF-16 ones . en.wikipedia.org/wiki/Code_page it seems chcp 1201(UTF-16BE) doesn't work. chcp 1201 says "Invalid codepage". chcp 1200(UTF-16LE) says it too. According to this sqlsnippets.com/en/topic-13410.html "UTF-16 code pages are not supported in Command Prompt windows." – barlop Mar 12 '11 at 11:28
  • @barlop: thanks, I have amended the answer to include the restrictions you noted – RedGrittyBrick Mar 12 '11 at 12:09
2

Using cmd /a type filename will translate a file from Unicode to ANSI.

cmd /u type filename can translate an ASCII file into a Unicode file using the current codepage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.