#1 18 Dec 2012 02:32

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 246
Website

[Undocumented] CHCP

Hello. I check by self, more info about CHCP command.
Reading the MSDN I found that in CONSOLE there are a two code pages: For the INPUT and for the OUTPUT.

Then, when you call to CHCP and provide a valid CODEPAGE, this utility set the same codepage for both: INPUT and OUTPUT.
But, when you call the CHCP command, chcp print the codepage of the INPUT assuming that it is the same of the OUPUT.

I write a little program in c for change the codepage of both. You can compile with tiny c for use it.

/*
codepage.c
Author: Carlos.
Date: 18 dec 2012
Examples of usage:
codepage
codepage IN 437 OUT 437
*/

#include <windows.h>
#define str_to_int(str) strtoul(str, (TCHAR **) NULL, 10)
                           
int main(int argc, char * argv[])
{
	UINT in_cp;
	UINT out_cp;
	
	/* Get the data */
	in_cp = GetConsoleCP();
	out_cp = GetConsoleOutputCP();
	
	if (argc == 3) {
		if ( ! _stricmp(argv[1], "IN") ) {
			in_cp = str_to_int(argv[2]);
		}
		else if ( ! _stricmp(argv[1], "OUT") ) {
			out_cp = str_to_int(argv[2]);
		}
	}
	else if (argc == 5) {
		if ( ! _stricmp(argv[1], "IN") ) {
			in_cp = str_to_int(argv[2]);
			if ( ! _stricmp(argv[3], "OUT") ) {
				out_cp = str_to_int(argv[4]);
			}
		}
		else if ( ! _stricmp(argv[1], "OUT") ) {
			out_cp = str_to_int(argv[2]);
			if ( ! _stricmp(argv[3], "IN") ) {
				in_cp = str_to_int(argv[4]);
			}
		}
	}
	SetConsoleCP(in_cp);
	SetConsoleOutputCP(out_cp);
	/* Ensure valid code pages */
	in_cp = GetConsoleCP();
	out_cp = GetConsoleOutputCP();
	
	/* Print the information */
	printf("IN=%u OUT=%u\n", in_cp, out_cp);
	
	return 0;
}

This is a screenshot of the usage and use of file with name ascii 219.txt and get your conclusions:

codepage_zps00cd0f5f.png

Last edited by carlos (18 Dec 2012 06:55)

Offline

#2 18 Dec 2012 06:55

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 246
Website

Re: [Undocumented] CHCP

Updated the c code.

Offline

#3 10 Sep 2013 16:52

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 246
Website

Re: [Undocumented] CHCP

I found that the concept of input codepage and output codepage can be demostrated with the native command: graftabl:

In this example, first we set input and output codepage to 437, and after set the output codepage to 850. As commented in previous post chcp show the input codepage. graftabl show the output codepage. graftabl only set the output codepage, chcp set input and output codepage.

C:\>chcp 437
Tabla de códigos activa: 437

C:\>graftabl 850
Tabla de códigos anterior: 437
Tabla de códigos activa:   850

C:\>chcp
Tabla de códigos activa: 437

C:\>graftabl /status
Tabla de códigos activa:   850

C:\>

Last edited by carlos (10 Sep 2013 16:53)

Offline

#4 10 Sep 2013 21:24

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] CHCP

graftabl is not available for system with higher versions than xp...

Offline

#5 11 Sep 2013 01:24

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 246
Website

Re: [Undocumented] CHCP

npocmaka wrote:

graftabl is not available for system with higher versions than xp...

It is available in windows 7 pro.

Offline

#6 11 Sep 2013 02:18

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Undocumented] CHCP

It's in em all by the look of it

http://technet.microsoft.com/en-us/libr … 31969.aspx

Last edited by foxidrive (11 Sep 2013 02:19)

Offline

#7 11 Sep 2013 06:02

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] CHCP

foxidrive wrote:

I saw that.But it's not available on my Vista Ultimate.Will check it on the 7...

Offline

#8 11 Sep 2013 07:16

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] CHCP

nope...

Offline

#9 11 Sep 2013 11:07

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Undocumented] CHCP

c:\Windows\System32\graftabl.com in Win 8 32 bit.  Maybe yours is 64 bit.

Offline

#10 11 Sep 2013 12:56

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] CHCP

foxidrive wrote:

c:\Windows\System32\graftabl.com in Win 8 32 bit.  Maybe yours is 64 bit.

Yes.My both machines (7&Vista) are 64b. None of them have the command.

Offline

#11 11 Sep 2013 15:16

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Undocumented] CHCP

You can see it is a com file in 32 bit windows 8, like debug.com which you don't have in your 64 bit machines either (coz 64 bit can't run .com 16 bit files)

That would be the reason...

Last edited by foxidrive (11 Sep 2013 15:17)

Offline

#12 13 Sep 2013 06:18

dbenham
Member
From: U.S. east coast
Registered: 15 Apr 2012
Posts: 111

Re: [Undocumented] CHCP

Very interesting.

After reading this, I googled a bit, and found that PowerShell provides independent control of both Input and Output code pages: http://stackoverflow.com/a/5808445/1012053. The nice thing is, the console preserves the code page settings even after PowerShell terminates smile

powershell [Console]::OutputEncoding=[System.Text.Encoding]::GetEncoding(850);[Console]::InputEncoding=[System.Text.Encoding]::GetEncoding(437)

This should help with 64 bit machines.


Dave Benham

Offline

Board footer

Powered by FluxBB