我有一个脚本,该脚本从日志文件中读取一些带有特殊字符的文本。日志文件由其他程序以UTF-8格式创建。
这是我的脚本:
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
读取文件的输出类似于“Nãopossível”的“NÃoéspossÃvel”理解
有帮助吗?
答案 0 :(得分:0)
能够读取UTF-8文本文件。使用ADODB.Stream
,因为Scripting.FileSystemObject
只能读取ASCII文本文件(MS Doc)。
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
Não é possível
사리원 불고기
应该提示“确切内容”。