gpt4 book ai didi

batch-file - chcp 65001 和 .bat 文件

转载 作者:行者123 更新时间:2023-12-03 01:07:12 24 4
gpt4 key购买 nike

我在 Windows shell 中使用 chcp 65001 命令时遇到问题。

我需要在文件夹中生成文件列表。所以我运行 cmd.exe,输入

cd folder
dir /B /O:N > list_of_files.txt

它有效,但我遇到了某些文件名中的特殊非 ASCII 字符的问题。所以我添加了chcp 65001

一切正常,但是当我将这些命令放入 .bat 文件中时,脚本不起作用。

所以

cd folder
chcp 65001
dir /B /O:N > list_of_files.txt

不生成列表。

cd folder
chcp 65001 && dir /B /O:N > list_of_files.txt

以及

cd folder
chcp 65001 > nul && dir /B /O:N > list_of_files.txt

生成列表,但使用默认编码:/。

在 cmd.exe 中一切正常,但在 .bat 文件中则不行。

我已阅读主题:stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called ,但没有帮助。

编辑:我部分解决了我的问题,将 chcp 65001 更改为 chcp 1250 ,因为所有字符都采用这种编码。但实际上这并不能回答问题。

最佳答案

“chcp 65001”在Windows 7之前不起作用。它将导致批处理立即终止。没有解决方法。

我已经通过直接测试 2003、XP、Vista、2008、7、8 和 10 验证了这一点。

关于batch-file - chcp 65001 和 .bat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32182619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com