223

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,536

9 Answers9

154

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

Nils Magne Lunde
  • 2,672
  • 1
  • 18
  • 14
86

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,483
Isti115
  • 1,242
68

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
  • 117
juca
  • 689
46

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
6

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
  • 69
  • 1
  • 1
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.

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

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

2

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

@ECHO OFF
CHCP 65001 > nul