0

I am designing GUI for iperf3.exe. When I run iperf3.exe, the text box appears after it finishes the process. I want to read output while doing the process. I try async method and task but all the time process finish then read output. I can read output if I write ping commands, but can't read output of iperf3.exe at real time. How can I read output while iperf3.exe running?

 private void CMDyazma(string commandline_server)
    {
        try
        {       string output = "";
                bool boolean = false;
                string eOut = null;
                Process pr = new Process();
                pr.StartInfo.UseShellExecute = false;
                pr.StartInfo.RedirectStandardOutput = true;
            
                pr.StartInfo.RedirectStandardError = true;
            
                pr.StartInfo.CreateNoWindow = true;
                pr.StartInfo.FileName = "D:\\iperf3\\iperf3.exe";

            
                pr.StartInfo.Arguments = commandline_server;
            
                pr.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                pr.ErrorDataReceived += new DataReceivedEventHandler(ErrorHandler);

                pr.Start();
                //pr.OutputDataReceived += new DataReceivedEventHandler(pr_OutputDataReceived);
                // pr.OutputDataReceived += (s, e) => { e.Data ; };
            
           
                pr.BeginOutputReadLine();
                //string output1 = pr.StandardOutput.ReadToEnd();
                pr.BeginErrorReadLine();
                pr.WaitForExit(1000);
     }
        catch
        {
            //return "Error: " + e.Message;
        }

    }
    private static void OutputHandler(object sender, DataReceivedEventArgs e)
    {
        if (!string.IsNullOrEmpty(e.Data))
        {
            
            Console.WriteLine("Output: " + e.Data);
        }
    }
    private static void ErrorHandler(object sender, DataReceivedEventArgs e)
    {
        if (!string.IsNullOrEmpty(e.Data))
        {

            Console.WriteLine("Error: " + e.Data);
        }
    }
Psydk00
  • 1
  • 1
  • If you want us to help you with your code, add it in a code box, _(by copying and pasting it)_. We are not going to try to view an image of the code, then manually type it, in order to begin to help you. – Compo Aug 16 '23 at 09:53
  • This is my first time posting on the forum, sorry for my inexperience. – Psydk00 Aug 17 '23 at 12:59

0 Answers0