如何在批处理文件中输出中文单词? [英] How to output Chinese word in batch file?

查看:48
本文介绍了如何在批处理文件中输出中文单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码按批处理文件输出中文单词.

I am using following code to out put Chinese word by batch file.

@echo off

echo  成功 
echo  失敗 
echo  開始 

但是它显示乱码.

 ??
 憭望?
 ??

如何在批处理文件中输出中文单词?

How to output Chinese word in batch file?

推荐答案

将批处理文件类型保存为ANSI文件扩展名:

Save batch file type to ANSI file extension:

  1. 使用Windows文本编辑器
  2. 选择另存为..."
  3. 编码"中选择"ANSI"
  4. 按保存"按钮.

执行bat文件,它将显示正确的单词.

execute the bat file and it will show correct word.

 成功
 失敗
 開始

感谢 eryksun 推荐:

通常,您需要使用可以将批处理文件另存为UTF-8而无需BOM的编辑器,例如notepad ++.然后在顶部运行命令chcp.com65001.控制台中的UTF-8代码页(65001)有问题,因此,您实际上应该只是暂时执行此操作,即,首先保存先前的代码页,然后将字符串读入环境后将其还原变量.

More generally you need to use an editor that can save the batch file as UTF-8 without a BOM, such as notepad++. Then at the top run the command chcp.com 65001. The UTF-8 codepage (65001) is buggy in the console, so you should really only do this temporarily, i.e. first save the previous codepage and restore it after reading the strings into environment variables.

这篇关于如何在批处理文件中输出中文单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆