R
robert.waters
I have a thread that uses the Process object to execute an external
script, and redirects the stdout and stderr output from that script
asyncronously (using BeginErrorReadLine and BeginOutputReadLine and a
DataReceivedEventHandler for each output handle).
However, the output is not being sent to the event handlers when it is
flushed in the external script.
The (perl) script is simple, it just iterates and prints a string to
stdout when the iterator is even, and a string to stderr when it is
odd; output is flushed after each print. When I run this script in
the console, I get the expected output (alternating stdout/stderr
strings). However, when I run this script using the Process object,
the strings appear in bunches of one or the other. (If I add a
1/10th second delay to the perl script during each iteration, the
Process object works as expected, most of the time.)
So, the event handlers are not being triggered when output from the
script is flushed; they seem to have their own internal buffers that
flush at an indeterminate (to me) time. The
Process.StandardOutput.BaseStream object has a Flush() method, but
this cannot be called when the stream is being read asynchronously.
Please help!
Thanks,
Robert Waters
script, and redirects the stdout and stderr output from that script
asyncronously (using BeginErrorReadLine and BeginOutputReadLine and a
DataReceivedEventHandler for each output handle).
However, the output is not being sent to the event handlers when it is
flushed in the external script.
The (perl) script is simple, it just iterates and prints a string to
stdout when the iterator is even, and a string to stderr when it is
odd; output is flushed after each print. When I run this script in
the console, I get the expected output (alternating stdout/stderr
strings). However, when I run this script using the Process object,
the strings appear in bunches of one or the other. (If I add a
1/10th second delay to the perl script during each iteration, the
Process object works as expected, most of the time.)
So, the event handlers are not being triggered when output from the
script is flushed; they seem to have their own internal buffers that
flush at an indeterminate (to me) time. The
Process.StandardOutput.BaseStream object has a Flush() method, but
this cannot be called when the stream is being read asynchronously.
Please help!
Thanks,
Robert Waters