Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Help! Stream output from dos program in realtime (http://www.go4expert.com/forums/help-stream-output-dos-program-realtime-t8954/)

E4tH879 20Feb2008 22:18

Help! Stream output from dos program in realtime
 
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


E4tH879 21Feb2008 00:13

Resolved RE: Help! Stream output from dos program in realtime
 
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



All times are GMT +5.5. The time now is 14:56.