0

I have a script that reads from a log file some text with especial characters . The log file is created by other program in a UTF-8 format.

This is my script:

If iExitCode <> 0 Then
    Dim objFS, objFil, sLine, DoRead
    oMsg.HTMLBody = oMsg.HTMLBody & "<br><br>" & "Erro(s) e/ou Aviso(s)" & "<br>" & "____________________________"
    If DoDebug Then WScript.Echo "Scanning Log File"
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objFil = objFS.OpenTextFile(sLogFile, 1) ' OPEN LOG FILE FOR READING
    DoRead = True
    Do Until objFil.AtEndOfStream
        If DoRead Then sLine = objFil.ReadLine
        DoRead = True
        If DoDebug Then WScript.Echo "Readline1 = " & sLine
        If InStr(sLine, sLogFileError       ) > 0 _
        Or InStr(sLine, sLogFileWarning     ) > 0 _
        Or InStr(sLine, sLogFileSeriousError) > 0 Then
            If ( InStr(sLine, sLogFileError       ) > 0 And IncludeErrorsInReport   ) _
            Or ( InStr(sLine, sLogFileWarning     ) > 0 And IncludeWarningsInReport ) _
            Or ( InStr(sLine, sLogFileSeriousError) > 0 And IncludeErrorsInReport   ) Then
                    oMsg.HTMLBody = oMsg.HTMLBody & "<br><br>" & sLine
            End If
            If Not objFil.AtEndOfStream Then
                sLine = objFil.ReadLine
                If DoDebug Then WScript.Echo "Readline2 = " & sLine
                Do Until objFil.AtEndOfStream Or Left(sLine,1) = "["
                    oMsg.HTMLBody = oMsg.HTMLBody & "<br>" & sLine
                    sLine = objFil.ReadLine
                    If DoDebug Then WScript.Echo "Readline3 = " & sLine
                Loop
                DoRead = False
            End If
        End If
    Loop
    objFil.Close
End If

The file read output is something like this "Não é possìvel" instand of "Não é possível"

Any help?

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
Sagitario
  • 1
  • 1

1 Answers1

0

To able to read the UTF-8 Text File. Use ADODB.Stream, because Scripting.FileSystemObject can read only ASCII text files (MS Doc).


Sample Code

Option Explicit

Dim objStream, strData

Set objStream = CreateObject("ADODB.Stream")

objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("C:\Sample.txt")

strData = objStream.ReadText()

objStream.Close
Set objStream = Nothing

WScript.Echo strData

Content of a Sample.txt

Não é possível
사리원 불고기

It should be prompt the Exact Content.

  • Thank you for that, but I already try to use ADODB.Stream on my script, but can't put it work... I dont know what I'm doing wrong. Thank you in advance – Sagitario Nov 16 '18 at 14:35
  • I already read the file, but end with other error. The ADOBD.Stream don't support AtEndOfStream. What is the replace? Regards, – Sagitario Nov 22 '18 at 13:06