Constant reading console stream in C #

I want to read the continuation of cmd output stream in C #. I know that I can redirect a standard output stream and read it. Below is the code:

        System.Diagnostics.ProcessStartInfo pi= new System.Diagnostics.ProcessStartInfo(ProgramPATH,Params);
        pi.RedirectStandardOutput = true;
        pi.UseShellExecute = false;
        pi.CreateNoWindow = true;

        System.Diagnostics.Process proc= new System.Diagnostics.Process();
        proc.StartInfo = pi;
        proc.Start();

        string result = proc.StandardOutput.ReadToEnd();

But this gives the whole result right away. What if I issue a command pingwith an argument -t? How can I read this stream continuously?

+3
source share
1 answer

ReadToEnd, , , , . Read ReadLine. , OutputDataReceived. ( , BeginOutputReadLine, - . MSDN.)

, , , , , , . .

+9

Source: https://habr.com/ru/post/1793100/


All Articles