进程返回不支持法语字符vb.NET

时间:2014-11-17 08:10:14

标签: vb.net character-encoding

我正在尝试用VB.NET启动一个进程:

    MyProcess = New Process
    With MyProcess.StartInfo
        .FileName = "CMD.EXE"
        .UseShellExecute = False
        .CreateNoWindow = True
        .RedirectStandardInput = True
        .RedirectStandardOutput = True
        .RedirectStandardError = True
    End With
    MyProcess.Start()
    MyProcess.BeginErrorReadLine()
    MyProcess.BeginOutputReadLine()

但答案很糟糕,因为不支持法语字符:

Private Sub MyProcess_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.OutputDataReceived
    Debug.Print("Process Return=" & e.Data)
    processOutput = processOutput + e.Data + vbCrLf
End Sub

它回归如下:

流程返回= Vous tes d,j ... connect,sur VPN。 Process Return = La commande a,t,ex,cut,e。

有没有人知道如何获得所有法国人? 谢谢你

2 个答案:

答案 0 :(得分:0)

也许你必须在开始这个过程之前定义另一个编码?

Imports System.Text

    MyProcess = New Process
    With MyProcess.StartInfo
        .FileName = "CMD.EXE"
        .UseShellExecute = False
        .CreateNoWindow = True
        .RedirectStandardInput = True
        .RedirectStandardOutput = True
        .RedirectStandardError = True

        .StandardErrorEncoding = Encoding.UTF8;  ' <- here
        .StandardOutputEncoding = Encoding.UTF8; ' <-
        ' or any other encoding.
    End With
    MyProcess.Start()
    MyProcess.BeginErrorReadLine()
    MyProcess.BeginOutputReadLine()

但无法保证这可行。需要对该过程进行测试才能看到..

答案 1 :(得分:0)

我找到了一种方法: 我先执行此命令:&#34; chcp 1252&#34; 现在它的工作!!!