代码页 850 有效,65001 失败!没有对“call foo.cmd”的响应。内部命令工作正常
这个问题基本上就说明了问题。
我使用的是 Windows XP Pro Service Pack 3
ComSpec=C:\WINDOWS\system32\cmd.exe
我通过“开始”...“运行对话框”... cmd.exe 启动了控制台
这是我的控制台的“视图”:
命令,然后是输出(和我的 // 注释)
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
上面的工作正常(如预期)。 Windows 国度里的一切都是幸福的, 但是当我切换到代码页 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 :)
这里发生了什么(没有发生)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的是,它实际上根本没有运行它。如果您执行以下操作:
您将什么也得不到。它不仅缺少输出,而且根本没有运行(通过将
start .
放在echo
行之前即可证明)。在代码页 850 中,资源管理器运行,但在代码页 65001 中则不然。关于此问题有一些讨论 此处。你可以让你的脚本运行:
所以这似乎是启动命令文件时出现的某种问题,但只有在输入命令之前代码页为 65001 时!
鉴于
cmd.exe
中的挑剔支持,网络上的其他人似乎认为 PowerShell 可能是一个不错的选择。这是一个你必须自己评估的决定,但是,我自己在一个大型组织中工作,使用许多工具来完成同样的工作,我怀疑微软将把任何增强工作放在 PowerShell 而不是旧的命令 shell 后面。他们的资源很大,但并非无限。Interesting, it's not actually running it at all. If you do the following:
you get nothing. It's not just missing output, it's not running at all (as evidenced by putting
start .
before theecho
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:
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.造成这种情况的原因是,Windows xp 的 cmd.exe 使用值为 1 的参数 dwFlags 内部调用函数 MultiByteToWideChar 时。文档中这样说:“对于 UTF-8 dwFlags 必须设置为 0。否则,该函数将失败” 。
此处的补丁: http://consolesoft.com/p/cmd -xp-65001-fix/index.html
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