簡體   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