使用vbscript将中文字符写入文本文件 [英] Write Chinese chars to a text file using vbscript
问题描述
我正在尝试使用$ p
$ b
I'm trying to write some Chinese characters to a text file using
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set outputFile = myFSO.OpenTextFile(getOutputName(Argument, getMsiFileName(Wscript.Arguments)), forWriting, True)
outputFile.WriteLine(s)
变量 s
包含一个我从其他文件读取的汉字。我回显 s
的值,我可以在屏幕上正确看到s。但是,由于某些原因,脚本在 outputFile.WriteLine(s)
之后停止运行,而不返回任何错误消息。
The variable s
contains a Chinese character that I read from the other file. I echo s
value and I can see the s correctly in the screen. However, for some reason the script stops running after outputFile.WriteLine(s)
without returning any error message.
我缺少什么吗?
推荐答案
也许与字符编码有关。尝试直接在 OpenTextFile
方法的最后一个参数中为文件指定Unicode格式:
Maybe it's got something to do with character encoding. Try directly specifying the Unicode format for the file in the last parameter of the OpenTextFile
method:
Const Unicode = -1
Set outputFile = myFSO.OpenTextFile(getOutputName(Argument, getMsiFileName(Wscript.Arguments)), forWriting, True, Unicode)
此外,您还需要在写入文件后关闭文件:
Also, you need to close the file after writing to it:
outputFile.Close
如果这样做没有帮助,请尝试使用 AnthonyWJones建议。
If this doesn't help, try error handling like AnthonyWJones suggested.
这篇关于使用vbscript将中文字符写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!