I am looking for a way to read a standard output byte by byte from an external command line application.
The current code works, but only when adding a new line. Is there a way to read the current byte of the byte input so that I can update the user with progress.
Ex)
Proccesing file
0% 10 20 30 40 50 60 70 80 90 100%
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
xxxxxx
A x is added every few minutes in a console application, but not in my C # Win form, as it only updates after the current line (end) is completed
Code example:
Process VSCmd = new Process();
VSCmd.StartInfo = new ProcessStartInfo("c:\\testapp.exe");
VSCmd.StartInfo.Arguments = "--action run"
VSCmd.StartInfo.RedirectStandardOutput = true;
VSCmd.StartInfo.RedirectStandardError = true;
VSCmd.StartInfo.UseShellExecute = false;
VSCmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
VSCmd.StartInfo.CreateNoWindow = true;
VSCmd.Start();
StreamReader sr = VSCmd.StandardOutput;
while ((s = sr.ReadLine()) != null)
{
strLog += s + "\r\n";
invoker.Invoke(updateCallback, new object[] { strLog });
}
VSCmd.WaitForExit();
source
share