本文介绍了如何在文本框中显示iperf cmd提示的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iperf-2.0.5-2-win32工具来查找网络带宽。我在c#中编写代码,打开cmd提示符,传递iperf参数以启动服务器端&客户端。 iperf-2.0.5-2-win32 exe不会直接打开,只需要通过cmd提示打开。目前输出(传输速率和带宽)显示在cmd提示符本身上。我希望这些输出显示在文本框中我也尝试过StreamReader。但它需要null,我也尝试过OutputDataReceived Event,它也取空。找到了很少的ipconfig和amp;代码ping.but那些没有使用iperf代码。

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帮助我。早期的回复表示感谢


Plz help me.Earlier responses are appreciated Thanks

推荐答案

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,


这篇关于如何在文本框中显示iperf cmd提示的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:11