|
-
Mar 22nd, 2015, 11:46 AM
#1
Process StandardOutput buffer size
When using a process with redirected output to run a third party app, rather than seeing the output 'as it happens', I get chunks of output every few minutes.
I'm guessing this is due to the buffer size, which I assume needs to fill before output is made available. Is there anyway of changing that buffer size? The process is running continuously (I am not waiting for it to exit).
I have tried several ways of doing this including a C# version http://www.codeproject.com/Articles/...-C-Application, BGW, Threading etc.) and the behaviour is always the same. I most recently used some code adapted from a post (credit to TnTinMn).
Code:
Private Sub StartProcess(ByVal command)
Dim ProcessInformation As New Diagnostics.ProcessStartInfo
With ProcessInformation
.FileName = "cmd.exe"
.Arguments = "/k " & command
.UseShellExecute = False
.RedirectStandardOutput = True
.RedirectStandardError = True
.RedirectStandardInput = True
.CreateNoWindow = True
End With
p = New Process()
p.StartInfo = ProcessInformation
p.EnableRaisingEvents = True
AddHandler p.OutputDataReceived, AddressOf OutputHandler
AddHandler p.ErrorDataReceived, AddressOf ErrorHandler
AddHandler p.Exited, AddressOf ProcessExitedHandler
p.Start()
p.BeginOutputReadLine()
p.BeginErrorReadLine()
End Sub
Private Sub OutputHandler(ByVal sendingProcess As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(delAppendOutput, New Object() {e})
End Sub
Private Sub ErrorHandler(ByVal sendingProcess As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(delAppendError, New Object() {e})
End Sub
Private Sub AppendOutput(ByVal e As DataReceivedEventArgs)
If Not String.IsNullOrEmpty(e.Data) Then tbOutput.AppendText(e.Data & System.Environment.NewLine)
End Sub
Private Sub AppendError(ByVal e As DataReceivedEventArgs)
If Not String.IsNullOrEmpty(e.Data) Then tbOutput.AppendText(e.Data & System.Environment.NewLine)
End Sub
Private Sub ProcessExitedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
CleanUpProcess()
End Sub
Private Sub CleanUpProcess()
If p IsNot Nothing Then
RemoveHandler p.Exited, AddressOf ProcessExitedHandler
RemoveHandler p.OutputDataReceived, AddressOf OutputHandler
If Not p.HasExited Then p.Kill()
p.Dispose()
p = Nothing
End If
End Sub
Any ideas appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|