carlos
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.
Code: Select all
/*
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;
}

Last edited by carlos (18 Dec 2012 06:55)
----------------------------
#2 18 Dec 2012 06:55
carlos
Updated the c code.
----------------------------
#3 10 Sep 2013 16:52
carlos
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.
Code: Select all
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:\>
----------------------------
#4 10 Sep 2013 21:24
npocmaka
graftabl is not available for system with higher versions than xp...
----------------------------
#5 11 Sep 2013 01:24
carlos
It is available in windows 7 pro.npocmaka wrote:
graftabl is not available for system with higher versions than xp...
----------------------------
#6 11 Sep 2013 02:18
foxidrive
It's in em all by the look of it
https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
Last edited by foxidrive (11 Sep 2013 02:19)
----------------------------
#7 11 Sep 2013 06:02
npocmaka
I saw that.But it's not available on my Vista Ultimate.Will check it on the 7...foxidrive wrote:
It's in em all by the look of it
https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
----------------------------
#8 11 Sep 2013 07:16
npocmaka
nope...
----------------------------
#9 11 Sep 2013 11:07
foxidrive
c:\Windows\System32\graftabl.com in Win 8 32 bit. Maybe yours is 64 bit.
----------------------------
#10 11 Sep 2013 12:56
npocmaka
Yes.My both machines (7&Vista) are 64b. None of them have the command.foxidrive wrote:
c:\Windows\System32\graftabl.com in Win 8 32 bit. Maybe yours is 64 bit.
----------------------------
#11 11 Sep 2013 15:16
foxidrive
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)
----------------------------
#12 13 Sep 2013 06:18
dbenham
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

Code: Select all
powershell [Console]::OutputEncoding=[System.Text.Encoding]::GetEncoding(850);[Console]::InputEncoding=[System.Text.Encoding]::GetEncoding(437)
Dave Benham