简体   繁体   中英

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

This is the program I wrote to open cmd, run IPERF as a client . After connecting with the server, it is supposed to show the bandwidth of the network. But the command prompt closes and the information I require is only available at the server side.

How do I get the information and display it in a MessageBox ?

Any form of assistance is most appreciated.

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); }

Have you tried "cmd /k"? It should prevent the terminal from closing after completion of your argument.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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