0

I simpily made a consol app which is a TCP-server if i start the normal way like go to the .exe and start with click it works normaly soo not that is the problem as i think. What i want to do is just read the last line from that consol Here is my code I got this code from another website

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

And my problem is when i start this code with the Go sub the consol app show up for a second then it close by that second before it close it read the first two line then close, Before you ask in the consol app there is this line Console.ReadLine()

I am totally have no idea what i can do.

Thanks for any help

Romeo Berenyi
  • 19
  • 1
  • 5
  • Where does a RichTextBox come from? Are you running a Form somewhere? – Jimi Apr 26 '19 at 16:44
  • Consol app is a different app this is a form based app and i included that line – Romeo Berenyi Apr 26 '19 at 16:45
  • 1
    Well, add `p.EnableRaisingEvents = True`, subscribe to the `Exited` event and see what is the `ExitCode`. Or add `p.WaitForExit`, also redirect standard error (`p.StartInfo.RedirectStandardError = True`) adding `p.BeginErrorReadLine()` and read the error output. You could also keep the console window open, so you see what happens – Jimi Apr 26 '19 at 16:51
  • See an example [here](https://stackoverflow.com/a/51682585/7444103). Anyway, it's quite possible that the console app just closes because of an uncaught error. – Jimi Apr 26 '19 at 17:01
  • 1
    Far fetch guess here.. when you run server.exe, it doesn't have the same running folder and can't find files. – the_lotus Apr 26 '19 at 17:34

0 Answers0