Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write Chinese chars to a text file using vbscript

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) 

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.

Am I missing something?

like image 540
Carlos Blanco Avatar asked Dec 01 '25 21:12

Carlos Blanco


1 Answers

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

If this doesn't help, try error handling like AnthonyWJones suggested.

like image 64
Helen Avatar answered Dec 04 '25 23:12

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!