204

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)

Regent
  • 2,346
  • 3
  • 16
  • 8
  • 3
    Note the purposed solution could break Windows' find.exe (which would cause problems with Android SDK build): http://superuser.com/questions/176737/why-find-exe-not-work-in-windows-7 – J Rao Jan 18 '15 at 05:24
  • Hm, when I use chcp 65001 my console windows crash when I do dir, but it helps to simply start cmd.exe with the /u flag (nb: it does use unicode by it is not reflected in chcp.com output) – eckes Jan 27 '15 at 18:58
  • 2
    Using the UTF-8 code-page also breaks the `more` command (it gives the misleading error message `Not enough memory.`) Opening the command-prompt with the `/U` switch does not help. – Synetech Mar 07 '16 at 22:00
  • 17
    The Windows console is riddled with bugs when the encoding is set to an unsupported multi-byte code page like 65001. Any software using the output counts of the Win32 WriteFile/ReadFile APIs will get the wrong results and consequently stuff build on that like the MSVCRT's implementation of the stdlib will produce mangled/repeated output and hang on input when confronted with non-ASCII. Until MS get around to fixing it — and it has been decades with no sign of that happening — globally changing console code page to 65001 is an **extraordinarily bad idea**. – bobince Oct 14 '16 at 08:51
  • 6
    **Any use of the `A` versions of Windows functions is broken.** All code needs to be ported to use the `W` versions. – Demi Apr 07 '17 at 14:42
  • 2
    `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP` is used as fallback for non-unicode (non-utf) environments, obviously you try to force it to a 'unicode', as you see it is controversal by definition. Windows hangs probably because some system stuff on boot depends on non-unicode charset to work. – venimus Aug 23 '17 at 15:00
  • @Demi that's no longer true nowadays. [Modern Windows supports UTF-8 as a locale](https://stackoverflow.com/a/63454192/995714) and Microsoft has started recommending to use the `A` version of Win32 APIs instead of the `W` version for portability – phuclv Jun 07 '21 at 13:52

9 Answers9

142

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

Nabi K.A.Z.
  • 420
  • 1
  • 6
  • 11
Nils Magne Lunde
  • 2,552
  • 1
  • 17
  • 14
  • 1
    @Regent In the question, the registry value you mentioned that worked for you is `@chcp 65001>nul`, while in this accepted answer, it is `chcp 65001`. What are the differences between the two? – galacticninja Mar 16 '15 at 08:41
  • 9
    @galacticninja simply putting `chcp 65001` will cause every opened command prompt to print 'Active code page: 65001' whilst `@chcp 65001>nul` will prevent any output. – Regent Mar 26 '15 at 15:51
  • 8
    `Autorun` is not present for me under Windows 8.1. – kleinfreund May 10 '15 at 09:09
  • Setting my console to UTF-8 made my console ding a lot when copy/pasting accented text into it, then discard the accented characters. Couldn't type them in either. – John Dvorak Jul 06 '16 at 07:31
  • https://imgur.com/RvZSlHi seem I don't have Autorun key to change, could I create a key with `autorun` name here? which type of it? – Luke Aug 23 '18 at 08:39
  • 4
    @kleinfreund @Luke: if `Autorun` is not present, you can add a _New_ _String Value_ with the contents of `@chcp 65001>nul` – Dacto Oct 23 '18 at 20:45
  • @NilsMagneLunde So, what is the point of this answer: https://stackoverflow.com/questions/388490 that says: "chcp 65001 is very dangerous." – Dr.jacky Dec 06 '18 at 08:06
  • 2
    @Dr.jacky Not sure exactly what they mean with dangerous. I've just answered the question of the OP. Whether you should do it or not is a different question. I believe there might be some issues with Python, so you may want to check that out before setting codepage to 65001 at least. – Nils Magne Lunde Dec 18 '18 at 06:59
  • And if you are NOT starting CMD, but just a random console utility, Autorun will not run… – AnrDaemon Sep 06 '19 at 09:10
  • Well, if you think it is dangerous, (yeah in fact adding to the registry and forcing it runs everytime, there is a potential caveat indeed), you may simply run `chcp 65001` anytime right in the command prompt whenever you need to display the unicode characters in the following outputs. Tested that this only affects the current command prompt instance. Another command prompt instance will not be affected. :) – midnite Jun 19 '20 at 12:12
  • On Win11 `Autorun` is not present, and I have to add a New String Value with name `Autorun` and content `@chcp 65001>nul` – oeter Jul 14 '22 at 20:18
62

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.)

Windows screenshot - Region Settings - UTF-8

Bob Stein
  • 1,383
  • 1
  • 16
  • 23
Isti115
  • 994
  • 10
  • 11
  • 12
    This is the best and correct answer for modern Windows. – CAD97 Apr 01 '20 at 21:06
  • 3
    This certainly did the job for me. However, it had a nasty side-effect: QuickBooks (I used 2017 Professional) suddenly failed to recognize any of my account names, since they contain Unicode characters, and this setting really messed things up with that software. Just a heads-up... – Mike Allen Apr 15 '20 at 18:42
  • 3
    Hmm, the system must have got used to a stripped version of those names or something similar. Never thought this would break stuff while fixing other things, but I guess you can never make a change without messing up something. (https://xkcd.com/1172/) Thanks for the information, I hope that it doesn't happen to many other people, but at least now they can be prepared. – Isti115 Apr 15 '20 at 19:24
  • 2
    Works. Would be interesting to be able replicate as a script. It seems to change a couple of cope page registries https://stackoverflow.com/a/57341868 to 65001 – CervEd Dec 15 '21 at 09:15
  • 1
    Microsoft calling a Windows feature "Beta". Looks like it must have unexpected side effects :-) It does the job for me though. – Serge Wautier Jan 07 '22 at 11:45
  • It does... For example font settings in PowerShell no longer "stick" - it always defaults to ugly raster font with this on. – Jonas Czech Mar 17 '22 at 16:16
  • 1
    This works but has side-effects as expected of a beta feature. In my box mercurial client stopped working (affecting even tortoise). When using the command line mercurial threw an "Invalid encoding" error, so I had to undo this change. – Loudenvier May 23 '22 at 18:11
59

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

@ECHO OFF
REM change CHCP to UTF-8
CHCP 65001
CLS

I saved at C:\Windows\System32 as switch.bat and 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.

Matthieu
  • 105
  • 6
juca
  • 599
  • 5
  • 2
  • 9
    Note that it will print `Active code page: 65001` to stdout. So if you are doing something like `CHCP 65001 && mycommand.exe` then you'll get the codepage printed out at the start. You need to `CHCP 65001 >nul && mycommand.exe` – frumbert Jun 12 '15 at 05:33
  • 1
    Why the CLS? :) – OMA Jan 24 '21 at 01:30
  • 1
    @OMA it's "CLear Screen" to start with an empty console instead of seeing the message "Active code page: 65001". But you could also use `>nul` to get rid of the message (and the `cls`). – Matthieu Jun 07 '21 at 09:44
  • 1
    @Matthieu : Yes, I know what CLS is for since I was little in the 80s ;-). The question was about what was the point in clearing the screen (that's why I wrote "Why the CLS?" and not "What's the CLS command for?". If it's just so the "Active code page" message is not visible, it's a bit of a crude way to do so (also, the user might not want to get rid of everything on the screen just because of changing a codepage). It's much better with the ">nul" approach you suggested. – OMA Jun 10 '21 at 21:39
  • @OMA I thought so. I'm old too ;) – Matthieu Jun 11 '21 at 09:24
44

Edit the Registry:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
"OEMCP"="65001"

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:

https://github.com/microsoft/cascadia-code

Zombo
  • 1
  • 24
  • 120
  • 163
6

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

PS> Set-ExecutionPolicy RemoteSigned
PS> New-Item -Path $Profile -ItemType file -Force
PS> notepad $Profile

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.

Freon Sandoz
  • 129
  • 2
  • 6
5

The command to change the codepage is chcp <codepage>. 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.

JColares
  • 59
  • 1
  • 1
  • This one worked perfectly for me. `-NoExit -Command "chcp 1252 > null"` also omits the message about the selected code page in the beginning. – CodeMonkey Aug 03 '18 at 08:53
3

Open in Powershell through Explorer still didn't work for me even though I've tried enabling that Beta Unicode feature in the language settings.

However, I've just found this worked.

[HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe]
"CodePage"=dword:0000fde9 

Manually changing the

From: https://www.zhihu.com/question/54724102

Daniel Cheung
  • 255
  • 3
  • 19
2

If you're using ConEmu then:

  1. Open up Settings from the upper right menu
  2. Go to Startup -> Environment
  3. Add chcp 65001 on a new line.
  4. Click "Save Settings".
  5. Close ConEmu and re-open it

enter image description here

1

Instead of changing the registry, you can instead create %HOMEPATH%\init.cmd.
Mine reads:

@ECHO OFF
CHCP 65001 > nul
user333869
  • 175
  • 1
  • 6