更改 .bat 文件中的代码页(Win7 与 Win Vista)
我在尝试更改 .bat 文件中的代码页时遇到一个奇怪的问题。
当我在 Windows 7 中执行以下 .bat 文件时,它执行得很好。
代码页发生更改,program.exe
被执行。
批处理文件:
chcp 65001
"D:\program.exe" /opt ÄiÜ
pause
但是,当我从 Windows Vista 启动 .bat 文件时,代码页会发生更改,然后退出批处理文件。
因此 program.exe
永远不会被执行。
但是,当我从命令行手动运行这两个命令时,它确实有效。
知道如何从 .bat 文件在 Windows Vista 下使其正常工作吗?
I have a strange issue while trying to change the codepage in a .bat file.
When I execute the following .bat file in Windows 7 it executes fine.
The codepage gets changed and program.exe
get executed.
The batch file:
chcp 65001
"D:\program.exe" /opt ÄiÜ
pause
However when I start the .bat file from Windows Vista the codepage gets changed and after that the batch file is exited.
So program.exe
never gets executed.
However when I run the two commands manually from the commandline it does work.
Any idea how to get this working under Windows Vista from .bat file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对我来说是新的,这适用于 Win7,在 Vista 和 XP 中,如果代码页更改为 65001,则批处理文件不起作用是正常的。
但是您可以使用 workaraound
这可以工作,因为在代码页更改时会缓存完整的块改变了。
在你的情况下(带有德语变音符号)你最好使用代码页 1252
It's new to me that this works with Win7, in Vista and XP it's normal that batch files aren't work if the codepage is changed to 65001.
But you can use a workaraound
This works, as the complete block is cached while the codepage is changed.
In your case (with german umlauts) you could better use the codepage 1252
您是否检查了
chcp
的返回代码(chcp 65001 & echo %ERRORLEVEL%
)?无论如何,尝试 chcp 65001 & "D:\program.exe" /opt äiÜ & chcp 850 。
Have you checked return code of
chcp
(chcp 65001 & echo %ERRORLEVEL%
)?Anyway, try
chcp 65001 & "D:\program.exe" /opt ÄiÜ & chcp 850
.我找到了一个适合我的(非常肮脏的)解决方案。
从表面上看,我想做的事情是不可能的。
我为使其工作所做的工作如下:
正如我所说,它很脏,但对我有用。
如果这里添加其他答案,我也会尝试这些。
I've found a (very dirty) solution which works for me.
By the looks of it it just isn't possible what I want to do.
What I've done to make it work is the following:
As I said it's pretty dirty but it works for me.
If other answer are added here I'll try those as well.
一个不太难看的解决方案,当我需要在批处理文件中使用带有特殊字符的文件名作为参数时,我使用它:
如果您在“dos”窗口中输入批处理文件内容(输入batchfilename.bat),您将看到文件名是正确的。 (它在文件查看器内置的totalcommander中看起来也是正确的,但在记事本中看起来很垃圾)
A less ugly solution, I use it when I need to use filenames with special characters as parameters in batch files:
If you type out the batchfile content in "dos" window ( type batchfilename.bat ) you will see the filename is correct. (It will also look correct in totalcommander built in fileviewer, but it will look garbage in notepad)