chethana mn

chethana mn

  • NA
  • 15
  • 9.8k

How to display output of iperf cmd prompt in textbox

May 21 2014 8:15 AM

I am using iperf-2.0.5-2-win32 tool to find network bandwidth. I have written codes in c# which opens the cmd prompt, pass iperf parameters to start server side & client side. iperf-2.0.5-2-win32 exe will not open directly, need to open through cmd prompt only.
At present the output(Transfer rate & Bandwidth) is displaying on cmd prompt itself. I want these output to be displayed in textbox
I have tried StreamReader also. But it takes null, I have also tried OutputDataReceived Event, its also taking null.
Found few codes for ipconfig & ping.but those were not working with iperf codes.


button_click event(),
{
      Process Client_proc = new Process();
              ProcessStartInfo Client_command = new ProcessStartInfo("cmd.exe");          
             string ip = txtIP.Text;
          
                Client_command.CreateNoWindow = true;
                Client_command.WindowStyle = ProcessWindowStyle.Hidden;
                Client_command.WorkingDirectory = @"E:\Iperf\RunEXE_Through_Application\iperf-2.0.5-2-win32";
                Client_command.Arguments = "/c START iperf -c " + ip;
                Client_proc.StartInfo = Client_command;
              
              
                Client_command.RedirectStandardOutput = true;
                Client_command.UseShellExecute = false;
                Client_proc.OutputDataReceived += new DataReceivedEventHandler(Client_proc_OutputDataReceived);
                Client_proc.Start();             
                Client_proc.BeginOutputReadLine();             
                Client_proc.WaitForExit();
}

  void Client_proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data != null)
            {
                string newLine = e.Data.Trim() + Environment.NewLine;
                MethodInvoker append = () => txtOutput.Text += newLine;
                txtOutput.BeginInvoke(append);
            }
        }

Plz help me.Earlier responses are appreciated
Thanks


Answers (1)