Process.StandardOutput buffer issue

  • Thread starter Thread starter Christopher Carlander
  • Start date Start date
C

Christopher Carlander

Hi,

I run a DOS command using a Process object. The command outputs a new line
of text to STDOUT every now and then as an indication of progress. I'd like
to capture that output and present it in a log window as soon as it's
written.

Problem: Reading from Process.StandardOutput seems to be limited to when the
internal StandardOutput buffer is full. The docs state "If the size of the
internal buffer was unspecified when the stream was constructed, its default
size is 4 kilobytes (4096 bytes).", but I'm not really in control of
creating that stream - it's done by the Process object.

Is there any way I can lower this internal buffer value? Or maybe there is a
better way of solving the problem?

Thanks,
Christopher

Code snippet:

Dim sOut = StreamReader
Dim ps = New Process
Dim s As String
ps.StartInfo.FileName = "cmd.exe"
ps.StartInfo.RedirectStandardOutput = True
ps.StartInfo.UseShellExecute = False
ps.StartInfo.Arguments = "/C " & MyDosCommand
ps.Start()

sOut = ps.StandardOutput

s = sOut.ReadLine
Do Until s Is Nothing
'This does not happen until 4K (or the entire buffer) has been
read
Debug.WriteLine(s)
s = sOut.ReadLine
Loop

If Not ps.HasExited Then ps.Kill()

(Btw, I've also tried to use Process.Read rather than ReadLine to specify
the length of the char array I'd like to get returned, but that doesn't help
as Read does not seem to read anything either until the buffer has filled
up.)
 
Hi

I have exactly the same problem I don't get all the information. Have you
found a solution yet

Regards

Peter
 
Back
Top