我简单地制作了一个consol应用程序,它是一个TCP服务器,如果我以正常方式启动,例如转到.exe
,然后单击就可以正常工作,那不是我认为的问题。我想做的就是从那个控制台读最后一行这是我的代码
我是从另一个网站获得此代码的
Sub Go()
Dim p As New Process
p.StartInfo.FileName = mainloc & "\ut\server.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
AddHandler p.OutputDataReceived, AddressOf HelloMum
MsgBox(p.StartInfo.FileName.ToString)
p.Start()
p.BeginOutputReadLine()
End Sub
Sub HelloMum(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
UpdateTextBox(e.Data)
End Sub
Private Delegate Sub UpdateTextBoxDelegate(ByVal Text As String)
Private Sub UpdateTextBox(ByVal Tex As String)
If Me.InvokeRequired Then
Dim del As New UpdateTextBoxDelegate(AddressOf UpdateTextBox)
Dim args As Object() = {Tex}
Me.Invoke(del, args)
Else
RichTextBox1.Text &= Tex & Environment.NewLine
End If
End Sub
我的问题是,当我用Go sub
启动此代码一秒钟后,consol应用程序出现一秒钟,然后在关闭前一秒钟关闭它,然后关闭它,读取前两行,然后关闭。 consol应用程序中有此行Console.ReadLine()
我完全不知道我能做什么。
感谢您的帮助