excel - WScript.Shell 以 UTF8 读取输出
问题描述
我正在尝试从 WScript.Shells Exec 返回值读取输出。有些行包含中文/德语/西里尔字符,如下所示:
Glas für Rahmen
问题是,我在 VBA 脚本中收到了“错误”的字符。
我可以更改我的字符集StdOut
吗?我通过 WScript.Shell 启动的可执行文件的开发人员确保输出为 UTF8。如果我在 CMD 中启动可执行文件,我可以看到正确的字符。
Private oShell As Variant
Private Sub Class_Initialize()
Set oShell = CreateObject("WScript.Shell")
End Sub
Public Function StartExeAndGetOutput(executable As String, arguments As String) As String
Dim returnValue As Object
Set returnValue = oShell.Exec(executable & " " & arguments)
Dim oOutput As Object
Set oOutput = returnValue.StdOut
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
StartExeAndGetOutput = s
End Function
解决方案
不幸的是你不能,但你可以理解什么是字符集,你可以为 UTF-8 “转换”或“转换”,标准输出是什么?
推荐阅读
- javascript - Angular 8嵌套拖放
- javascript - 使用条件退出 for 循环
- apache-spark - 一次性在 spark 数据帧上执行多个聚合,而不是多个慢速连接
- assembly - 64 位或使用 64 位寄存器的地址大小覆盖前缀
- scala - Scala嘲笑这种行为
- typescript - 在 Visual Studio 中将 typescript 错误报告为警告,并且不会使构建失败
- spring - 如何从 MONO/FLUX 中提取字符串值 -
- laravel - 从 json 获取嵌套数组的值
- c# - WPF 按钮效果
- android - org.jetbrains.kotlin.util.KotlinFrontEndException:分析表达式时出现异常