Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
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
Posted
Updated 21-May-14 2:31am
v2

1 solution

Hello,

I tried with following code and was able to read the output of the iperf program.
C#
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
p.StartInfo.FileName = "F:\\SCRAP\\IPREF\\iperf.exe";
p.StartInfo.Arguments = "-c 10.91.10.217 -p 8080";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
Console.WriteLine(output);

Here is the output I received
------------------------------------------------------------
Client connecting to 10.91.10.217, TCP port 8080
TCP window size: 64.0 KByte (default)
------------------------------------------------------------
[  3] local 10.91.105.145 port 55538 connected with 10.91.10.217 port 8080
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1897666874917397 bits  1920124492449476278251040091125s/sec

Regards,
 
Share this answer
 
Comments
Member 10590933 22-May-14 1:12am    
Thanks Prasad Khandekar. Its working fine now.But i need to arrange the output line by line.
I have used WorkingDirectory instead of FileName which was stoppijng me from getting the output,Now i have modified the code and able to get output without using any event.
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900