Changing code page in windows

chcp chcp

Изменяет активную кодовую страницу консоли. Changes the active console code page. Если используется без параметров, параметр chcp отображает номер активной кодовой страницы консоли. If used without parameters, chcp displays the number of the active console code page.

Синтаксис Syntax

Параметры Parameters

Параметр Parameter Описание Description
Задает кодовую страницу. Specifies the code page.
/? /? Отображение справки в командной строке. Displays help at the command prompt.

В следующей таблице перечислены поддерживаемые кодовые страницы и их страны, регионы или языки. The following table lists each supported code page and its country/region or language:

Кодовая страница Code page Страна, регион или язык Country/region or language
437 437 США United States
850 850 Многоязычная (латиница I) Multilingual (Latin I)
852 852 Славянские (латиница II) Slavic (Latin II)
855 855 Кириллица (Русский) Cyrillic (Russian)
857 857 Турецкий Turkish
860 860 Португальский Portuguese
861 861 Исландский Icelandic
863 863 Canadian-French Canadian-French
865 865 Скандинавская Nordic
866 866 русском языке Russian
869 869 Современный греческий Modern Greek
936 936 Китайский Chinese

Комментарии Remarks

В окне командной строки, использующем растровые шрифты, правильно отображается только кодовая страница изготовителя оборудования (OEM), установленная вместе с Windows. Only the original equipment manufacturer (OEM) code page that is installed with Windows appears correctly in a Command Prompt window that uses Raster fonts. Другие кодовые страницы отображаются правильно в полноэкранном режиме или в окнах командной строки, в которых используются шрифты TrueType. Other code pages appear correctly in full-screen mode or in Command Prompt windows that use TrueType fonts.

Вам не нужно подготавливать кодовые страницы (как в MS-DOS). You don’t need to prepare code pages (as in MS-DOS).

Программы, запускаемые после назначения новой кодовой страницы, используют новую кодовую страницу. Programs that you start after you assign a new code page use the new code page. Однако программы (кроме Cmd.exe), которые вы начали перед назначением новой кодовой страницы, продолжат использовать исходную кодовую страницу. However, programs (except Cmd.exe) that you started before assigning the new code page will continue to use the original code page.

Примеры Examples

Чтобы просмотреть текущую настройку кодовой страницы, введите: To view the active code page setting, type:

Появится сообщение следующего вида: Active code page: 437 A message similar to the following appears: Active code page: 437

Чтобы изменить активную кодовую страницу на 850 (многоязычный), введите: To change the active code page to 850 (Multilingual), type:

Если указанная кодовая страница является недопустимой, появляется следующее сообщение об ошибке: Invalid code page If the specified code page is invalid, the following error message appears: Invalid code page

CHCP.com

Change the active console Code Page. The default code page is determined by the Windows Locale.

This command is rarely required as most GUI programs and PowerShell now support Unicode. When working with characters outside the ASCII range of 0-127, the choice of code page will determine the set of characters displayed.

Programs that you start after you assign a new code page will use the new code page, however, programs (except Cmd.exe) that you started before assigning the new code page will use the original code page.

Code page Country/ Region/ Language
437 United States default code page in the US
850 Multilingual (Latin I) default code page in most of Europe
852 Slavic (Latin II)
855 Cyrillic (Russian)
857 Turkish
860 Portuguese
861 Icelandic
863 Canadian-French
865 Nordic
866 Russian
869 Modern Greek
1252 West European Latin
65000 UTF-7 *
65001 UTF-8 *

* The 65000/1 code pages are encoded as UTF-7/8 to allow to working with unicode data in 7-bit and 8-bit environments, however

Even if you use CHCP to run the Windows Console in a unicode code page, many applications will assume that the default still applies, e.g. Java requires the-Dfile option: java -Dfile.encoding=UTF-8

Unicode characters will only display if the current console font contains the characters. So use a TrueType font like Lucida Console instead of the CMD default Raster Font.

The CMD Shell (which runs inside the Windows Console)

CMD.exe only supports two character encodings Ascii and Unicode (CMD /A and CMD /U)

If you need full unicode support use PowerShell. There is still VERY limited support for unicode in the CMD shell, piping, redirection and most commands are still ANSI only. The only commands that work are DIR, FOR /F and TYPE, this allows reading and writing (UTF-16LE / BOM) files and filenames but not much else.

Code Pages

The number of supported code pages was greatly increased in Windows 7.
For a full list of code pages supported on your machine, run NLSINFO (Resource Kit Tools).

Files saved in Windows Notepad will be in ANSI format by default, but can also be saved as Unicode UTF-16LE or UTF -8 and for unicode files, will include a BOM.
A BOM will make a batch file not executable on Windows, so batch files must be saved as ANSI, not Unicode.

View the current code page:
chcp

Change the code page to Unicode/65001:
chcp 65001

“Remember that there is no code faster than no code”

Taligent’s Guide to Designing Programs

Joel Spolsky.
Powershell: All text input is automatically converted to Unicode.
Equivalent bash command (Linux): LANG — locale category environment variable & LC_* variables for locale category.

Change Console Code Page in Windows C++

I’m trying to output UTF8 characters in the Windows command line. I can’t seem to get the function, setConsoleOutputCP to work. I also heard that you had to change the font to «Lucida Grande» for it to work but I can’t get that working either. Can someone please provide me with a short example of how to use these functions to correctly output UTF-8 characters to the console?

Also I heard that those functions don’t work in Windows XP, is there a better alternative to those functions which will work in Windows XP?

4 Answers 4

Windows console doesn’t play nice with UNICODE and particularly with UTF-8.

Setting a console code page to utf-8 won’t work.

One approach is to use WideCharToMultiByte() (or something else) to convert the text to UTF-16, then MultiByteToWideChar() (or something else) to convert to a localised ISO encoding. The set the console code page to the ISO code page.

Its ugly, but it sort of works.

[I know this question is old and was about Windows XP, but it still seemed like a good place to drop this information so I (and maybe others) can find it again in the future.]

Support for Unicode in CMD windows has improved in newer versions of Windows. This program will work on Windows 10.

I made an RAII class to ensure the code page is restored because it would be rude to leave the code page changed if the user had purposely selected a specific one. All the Windows-specific code (SetConsoleOutputCP) is contained within that class. The definition of the use_utf8 variable in main changes the code page to UTF-8, and that code page will stay in effect until the variable is destructed at the end of the scope.

Note that I used the u8 prefix on the string literal, which is a newer feature of C++ to ensure that the string is encoded using UTF-8 regardless of the encoding used for the source file. You don’t have to use that feature if you have another way to make a string of valid UTF-8 text.

You still have to be sure that the CMD window is using a font that supports the glyphs you need. I don’t think there’s a way to get font linking automatically. But this will at least show a the replacement character if the font is missing the glyph. For example, on my window, the ¡Olé! looks right but the CJK glyph is shown approximately like � . If the user copies that replacement character, the clipboard will receive the original glyph, so they can paste it into other programs without any loss of fidelity.

Note that command line parameters you get from main ‘s argv will be in the original code page. One way to work around this is to get the unconverted «wide» command line with GetCommandLineW, convert it to UTF-8 with WideToMultibyte, and then parse it yourself. Alternatively, you can pass the result of GetCommandLineW to CommandLineToArgvW, which will parse it, and then you’d convert each argument to UTF-8.

Finally, note that changing the code page affects only the output. If you input text from the user, it arrives encoded using the original code page (often called the OEM code page).

TODO: Figure out input. SetConsoleCP isn’t doing what I think the documentation says it should do.

Change CodePage in CMD permanently?

My Windows cmd CodePage is now under 65001. Since I was doing some Android stuff and need to use console log, but forget how changing it now.

When using chcp 437 to change the CodePage back, it works. But if I start a new cmd window, it goes back.

How to do the chcp thing to make it pernament?

6 Answers 6

Here I found a better solution:

  1. Start -> Run -> regedit
  2. Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
  3. Add new String Value named: Autorun
  4. Change the value to ‘chcp 437’

Create a start up batch file that includes all the commands you want.

Then edit the registry to point to your start up file.

c:\startup.cmd

HKLM\SOFTWARE\Microsoft\Command Processor
AUTORUN=»C:\startup.cmd»

Command prompt code page always change back to the default 437 if you just use chcp 850 in cmd to change the active language code (850 = Multilingual (Latin I)). My system default language is set to English (437) although I’m Brazilian (language code 850). Once I need to show some special characters such as ã, õ, ç, I found that at Windows 10, under All Settings > Time & Language > Region & Language there is (at the top right corner) a link for Related settings — Additional date, time & regional settings. From there you’ll be redirected to Control Panel\Clock, Language, and Region. Click again on Region > Change Location and at the window Region, at the tab Administrative, change the Language for non-Unicode programs by clicking the button Change system locale and choosing some other that uses the code you need (In my case, Portuguese (Brazil) = code 850). Restart Windows and check if your command prompt is now set to the new language code (type chcp in cmd). For me, it solved the problem. There is also a Latin (Word) option on the list that I suppose is also code 850.

In the 1809 build of Windows 10 I’ve managed to permanently solve this by going to the system’s Language settings , selecting Administrative language settings , clicking Change system locale. and checking the Beta: Use Unicode UTF-8 for worldwide language support box and then restarting my pc.

This way it applies to all applications, even those ones that I don’t start from a command prompt! (Which was necessary for me, since I was trying to edit Agda code from Atom.)

Setting the default CMD/shell Codepage can be neatly done using the following command:

This will make the codepage 437 your default, but ONLY in the cmd/shell, meaning the rest of the OS is safe and the boot environment ist untouched. Instead of always changing the codepage whenever the cmd opens, the cmd will open in the specified codepage from start.

Change default code page of Windows console to UTF-8

Currently I’m running Windows 7 x64 and usually I want all console tools to work with UTF-8 rather than with default code page 850.

Running chcp 65001 in the command prompt prior to use of any tools helps but is there any way to set is as default code page?

Update:

Changing HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP value to 65001 appear to make the system unable to boot in my case.

Proposed change of HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun to @chcp 65001>nul served just well for my purpose. (thanks to Ole_Brun)

8 Answers 8

To change the codepage for the console only, do the following:

  1. Start -> Run -> regedit
  2. Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun]
  3. Change the value to @chcp 65001>nul

If Autorun is not present, you can add a New String

Personally, I don’t like changing the registry. This can cause a lot of problems. I created a batch file:

I saved at C:\Windows\System32 as switch.bat.

I created a link for cmd.exe on the Desktop.

In the properties of the cmd shortcut, changed the destination to: C:\Windows\System32\cmd.exe /k switch

Voilá, when I need to type in UTF-8, I use this link.

Edit the Registry:

Then restart. With this fix, if you are using Consolas font, it seems to lock PowerShell into a small font size. cmd.exe still works fine. As a workaround, you can use Lucida Console, or I switched to Cascadia Mono:

In the 1809 build of Windows 10 I’ve managed to permanently solve this by going to the system’s Language settings , selecting Administrative language settings , clicking Change system locale. and checking the Beta: Use Unicode UTF-8 for worldwide language support box and then restarting my pc.

This way it applies to all applications, even those ones that I don’t start from a command prompt!
(Which was necessary for me, since I was trying to edit Agda code from Atom.)

This can be done by creating a PowerShell profile and adding the command «chcp 65001 >$null» to it:

This doesn’t require editing the registry and, unlike editing a shortcut, will work if PowerShell is started in a specific folder using the Windows Explorer context menu.

The command to change the codepage is chcp . Example: chcp 1252 . You should type it in a Powershell window. To avoid the hassle of typing it everytime (if you always have to change the codepage), you may append it to the program’s command line. To do so, follow these steps:

  1. Right-click the Powershell icon on Start menu and choose «More» > «Open file Location».
  2. Right-click the Powershell shortcut and select «Properties».
  3. Add the following to the end of the «Target» command line: -NoExit -Command «chcp 1252»

Be happy. Don’t fuss with Windows Registry unless you have no other option.

Читайте также:  Как расширить оперативную память windows 10
Оцените статью