Archive for command prompt

Change Windows Command Prompt Code Page

Posted in Hacks with tags , , , on 2008-12-15 by mingaz

I sometimes have to code small programs to extract information from data sources like databases or LDAP servers (Active Directory included). Usually I don’t bother to code specific IO to write to a file. Instead, I write the output to standard output (stdout) and redirect the output of the program to a file.

On Windows this can be problematic since character encoding in the command prompt is usually different from the one used by Windows. There’s a great tutorial on character code issues here.

To solve this problem one should change the command prompt encoding (code page or OEM code page) to the equivalent Windows character set (Windows code page) using the command “chcp” like this (the example is for the WinLatin1, one should use the same used by Windows):

C:\> chcp 1252

If one needs to check de the currently used code page, should invoke the command without arguments, like this:

C:\> chcp

The Windows character set can be checked in “Regional Settings” or “Regional and Language Options”, in Control Panel.

To make the change permanent (to all command prompts opened in the future) do as follows:

  1. Open the Windows Registry (regedit.exe): Start->Run->regedit;
  2. Go to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage] and
  3. Change the “OEMCP” value to “1252″ (or the code page most suited for your needs);
  4. Restart your computer.