views:

226

answers:

2

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 ) 

variable s contains Chinese character that I read from 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?

+1  A: 

Try this:-

MsgBox "Writing Line"
On Error Resume Next
outputFile.WriteLine s '' # Removed ( ) that shouldn't be there.
MsgBox "Err " & Err.Number & ": " & Err.Description
On Error GoTo 0

What do you get?

AnthonyWJones
The script doesn't prompt anything, and the text file that the script is supposed to write to gets created but it's empty.
tou
+2  A: 

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.

Helen
+1, Nice catch, I missed that last parameter and was distracted by what still is in-explicable behaviour.
AnthonyWJones