Help! Stream output from dos program in realtime

E4tH879's Avatar, Join Date: Feb 2008
Newbie Member
ok well i am trying to create a gui for a dos program and i want to stream the output to a textbox, i have several buttons that start the dos program with different arguments and a button that kills the dos program. When I start my program and click a button that runs the dos program it works and outputs to the textbox but then if i click the button that kills it and then click that button again it doesnt output the programs output to my textbox anymore, the dos program still starts in the background though. I want to be able to start and stop the dos program and still output have it to the textbox in realtime.

Here a piece of the code

Code:
Private Sub DisplayOutput(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)
        OutText.AppendText(output.Data() & vbCrLf)
    End Sub

Public Function ziload(ByVal para As String)
        If (My.Computer.FileSystem.FileExists("ziphone.exe")) Then
            If (firsttime) Then
                With P
                    AddHandler P.OutputDataReceived, AddressOf DisplayOutput
                    .StartInfo.CreateNoWindow() = True
                    .StartInfo.UseShellExecute = False
                    .StartInfo.RedirectStandardInput = False
                    .StartInfo.RedirectStandardOutput = True
                    .StartInfo.FileName = "ziphone.exe"
                    .StartInfo.Arguments = para
                    .SynchronizingObject = OutText
                    firsttime = False
                End With
            End If
            P.Start()
            P.BeginOutputReadLine()
            disabler()
        Else
            MsgBox("File """ & "ziphone.exe" & """ does not exist !", MsgBoxStyle.Exclamation, "File not found")
            enabler()
        End If
    End Function

    Public Function closer()
        If Not (P Is Nothing) Then
            P.CancelOutputRead()
            P.Kill()
        End If
        enabler()
    End Function
0
E4tH879's Avatar, Join Date: Feb 2008
Newbie Member
Nevermind all i had to do is make the following changes

Code:
Private Sub DisplayOutput(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)
        OutText.AppendText(output.Data() & vbCrLf)
    End Sub

Public Function ziload(ByVal para As String)
        If (My.Computer.FileSystem.FileExists("ziphone.exe")) Then

            'CHANGE HERE
            P = New Process()
            'CHANGE HERE

            With P
                AddHandler P.OutputDataReceived, AddressOf DisplayOutput
                .StartInfo.CreateNoWindow() = True
                .StartInfo.UseShellExecute = False
                .StartInfo.RedirectStandardInput = False
                .StartInfo.RedirectStandardOutput = True
                .StartInfo.FileName = "ziphone.exe"
                .StartInfo.Arguments = para
                .SynchronizingObject = OutText
            End With
            P.Start()

            disabler()
            P.BeginOutputReadLine()
            P.EnableRaisingEvents = True

        Else
            MsgBox("File """ & "ziphone.exe" & """ does not exist !", MsgBoxStyle.Exclamation, "File not found")
            enabler()
        End If
    End Function

    Public Function closer()
        P.CancelOutputRead()
        P.Kill()
        OutText.AppendText(vbNewLine)
        enabler()
    End Function