4

The question basically explains the problem.

I'm using Windows XP Pro Service Pack 3
ComSpec=C:\WINDOWS\system32\cmd.exe
I launched the console via Start... Run-dialog... cmd.exe

Here is a "view" of my console:
The command, then the output (and my // comments)

C:\> chcp 850
Active code page: 850
// output is as expected

C:\> echo @chcp ^& REM 850>test850.cmd
// no output; as ecpected)

C:\> type test850.cmd
@chcp & REM 850
// output is as expected

C:\> call test850.cmd
Active code page: 850
// output is as expected

The above works fine (as expected). Things are happy in Windows-land, but the "call" FAILS when I switch to codepage 65001

C:\> chcp 65001
Active code page: 65001
// output is as expected

C:\> echo @chcp ^& REM 65001>test65001.cmd
// no output; as ecpected

C:\> type test65001.cmd
@chcp & REM 65001
// output is as expected

C:\> call test65001.cmd
// NO OUTPUT, NO ERROR, NO ANYTHING, NADA... other than frustration :)

What is happening (NOT happening) here?

Peter.O
  • 6,696
  • 4
  • 30
  • 37
  • I just ran these on my non-elevated cmd on Win7 x64 and got the expect output. what's your OS? – Franci Penov Aug 04 '10 at 00:57
  • @Franci: Specs (a good idea)... I'm using Windows XP Pro Service Pack 3 -- ComSpec=C:\WINDOWS\system32\cmd.exe (and I've added to the main question) – Peter.O Aug 04 '10 at 01:37
  • My experience is, it doesn't work even if you directly run a batch program in a cmd window when the current codepage is 65001. With msysgit (or mingw, I guess), if you try edit anything in vi/vim, you'll see garbage, instead of the actual text. – ryenus Oct 13 '11 at 02:22

2 Answers2

4

Interesting, it's not actually running it at all. If you do the following:

pax> echo echo yy >xx.cmd
pax> chcp 850
pax> xx
yy
pax> chcp 65001
pax> xx
pax> _

you get nothing. It's not just missing output, it's not running at all (as evidenced by putting start . before the echo line). In code page 850, Explorer runs, not so for code page 65001.

There's some discussion on the issue over here. You can get your script to run with:

chcp 65001 && xx.cmd && chcp 850

so it seems to be some sort of problem in starting command files but only when the code page is 65001 before you enter the command!

Others on the net seem to be suggesting that PowerShell may be a good choice, given the finicky support in cmd.exe. That's a decision you'll have to evaluate for yourself but, working in a large organisation myself with many tools to do the same job, I suspect Microsoft will be placing any enhancement efforts behind PowerShell rather the older command shell. Their resources are large but not unlimited.

Community
  • 1
  • 1
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Thanks... Your suggestion works: ( chcp 65001 && call test65001.cmd && chcp 850 )... and you've given a good overview of general picture... (but :( I don't have the required minimum points to mark your answer up ) --- It has brought up another issue, though (actually its my origin problem).. I thought sorting out the .cmd thing would also sort out .py Pythos scripts, They too did nothing... Now a .py script chucks a wobbly: Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: cp65001 --- Any thoughts, anyone? – Peter.O Aug 04 '10 at 03:08
  • Have a a look at http://bugs.python.org/issue6058 for a possible upcoming fix. And also, very few SOers are going to see that question buried in a comment to my answer. I would suggest doing it as another question so that you're more likely to get a response. – paxdiablo Aug 05 '10 at 03:22
1

The cause of this is when cmd.exe for windows xp internally call to the function MultiByteToWideChar using the argument dwFlags with the value 1. The documentation says this: "For UTF-8 dwFlags must be set to 0. Otherwise, the function fails".

A patch for it here: http://consolesoft.com/p/cmd-xp-65001-fix/index.html

carlos
  • 1,261
  • 1
  • 12
  • 15