繁体   English   中英

通过Visual Studio(C#)打开命令提示符,运行一些命令,然后通过文本框在命令提示符中显示结果详细信息

[英]open command prompt through Visual studio ( C# ) , run some commands and then display the resultant details in the command prompt through a text box

这是我为打开cmd而编写的程序,作为客户端运行IPERF。 与服务器连接后,应该显示网络的带宽。 但是命令提示符关闭,并且我需要的信息仅在服务器端可用。

如何获取信息并将其显示在MessageBox中?

非常感谢任何形式的协助。

string output;
ProcessStartInfo start = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe");
start.UseShellExecute = false;
start.ErrorDialog = false;
start.WindowStyle = ProcessWindowStyle.Normal;
start.RedirectStandardError = true;
start.RedirectStandardInput = true;
start.RedirectStandardOutput = true;
Process cmd = new Process();
cmd.StartInfo = start;
cmd.Start();
try
{
  Process.Start("cmd", "/C iperf -c " + IP_Address);
}
catch
{
}
Thread.Sleep(1000);
StreamReader outputReader = cmd.StandardOutput;
StreamReader errorReader = cmd.StandardError;         
output = outputReader.ReadToEnd();
MessageBox.Show( output );

try { Process.Start("cmd", "/C iperf -c " + IP_Address); }

您是否尝试过“ cmd / k”? 它应该防止您的参数完成后关闭终端。

try { Process.Start("cmd /k", "/C iperf -c " + IP_Address); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM