代码页 850 有效,65001 失败!没有对“call foo.cmd”的响应。内部命令工作正常

发布于 2024-09-12 22:12:01 字数 942 浏览 10 评论 0原文

这个问题基本上就说明了问题。

我使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹梦到西洲 2024-09-19 22:12:01

有趣的是,它实际上根本没有运行它。如果您执行以下操作:

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

您将什么也得不到。它不仅缺少输出,而且根本没有运行(通过将 start . 放在 echo 行之前即可证明)。在代码页 850 中,资源管理器运行,但在代码页 65001 中则不然。

关于此问题有一些讨论 此处。你可以让你的脚本运行:

chcp 65001 && xx.cmd && chcp 850

所以这似乎是启动命令文件时出现的某种问题,但只有在输入命令之前代码页为 65001 时!

鉴于 cmd.exe 中的挑剔支持,网络上的其他人似乎认为 PowerShell 可能是一个不错的选择。这是一个你必须自己评估的决定,但是,我自己在一个大型组织中工作,使用许多工具来完成同样的工作,我怀疑微软将把任何增强工作放在 PowerShell 而不是旧的命令 shell 后面。他们的资源很大,但并非无限。

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.

野却迷人 2024-09-19 22:12:01

造成这种情况的原因是,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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文