首页 > 解决方案 > 我无法弄清楚 ProcessStartInfo 并能够使用 Process.Start.StandardOutput.ReadToEnd 来显示命令行中发生的事情

问题描述

我试图在不打开命令行的情况下显示命令行界面中发生的事情。我知道 Process 类具有这种能力,但我很难使用 StandardOutput.ReadOnly。我将进程设置为一个按钮,然后单击后,我希望它显示命令行实际上正在连接的状态。想法?

    Private Sub EstablishConnection_Click(sender As Object, e As EventArgs) Handles EstablishConnection.Click

    ' One file parameter to the executable
    Dim sourceName1 As String = strXFileName
    Dim sourceName2 As String = strYFileName

    ' New ProcessStartInfo created
    Dim p As New ProcessStartInfo

    ' Specify the location of the binary
    p.FileName = "C:\Software\John\Doe"

    ' Use these arguments for the process
    p.Arguments = $"-Application  -Connect  -Example -E"" {stXFileName} "" -S"" {strYFileName} """

    ' Use a hidden window
    p.WindowStyle = ProcessWindowStyle.Hidden
    p.UseShellExecute = False
    p.RedirectStandardOutput = True
    p.RedirectStandardError = True
    p.RedirectStandardInput = True

    ' Start the process
    Process.Start(p)
    'Dim output As String = p.StandardOutputEncoding

    'Open the Status Screen form once connection is established
    StatusScreen.Show()
    Me.Hide()

End Sub

标签: vb.netvisual-studiovb.net-2010

解决方案


推荐阅读