我正在使用 iperf-2.0.5-2-win32 工具来查找网络带宽。我在 c# 中编写了代码,它打开 cmd 提示符,传递 iperf 参数来启动服务器端和客户端。iperf-2.0.5-2-win32 exe不会直接打开,只能通过cmd提示打开。目前输出(传输速率和带宽)显示在 cmd 提示符本身上。我希望这些输出显示在我也尝试过 StreamReader 的文本框中。但是它取null,我也尝试过OutputDataReceived Event,它也取null。找到了一些 ipconfig 和 ping 的代码。但这些代码不适用于 iperf 代码。
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);
}
}
请帮助我。感谢早期的回复谢谢