Using System. Diagnostics;
Using System. IO;
Private void btnRun_Click (object sender, EventArgs e)
{
TxtResult. Text = "";
ProcessCommand ("Ping.exe", this.txt Address. Text );
ProcessCommand ("Ping.exe", this.txt Address. Text );
}
Public void processCommand (string commandName, string argument)
{
ProcessStartInfo start = new ProcessStartInfo (commandName); // set the command line file for running the ping.exe file, which will be found by the File System
// If it is a temporary EXE file, you can specify the details, such as running winrar.exe
Start. WorkingDirectory = "d: \ 360Downloads \";
Start. Arguments = argument; // set Command Parameters
Start. CreateNoWindow = true; // The doscommand line window is not displayed.
Start. RedirectStandardOutput = true ;//
Start. RedirectStandardInput = true ;//
Start. UseShellExecute = false; // whether to specify the Operating System Shell Process Startup Program
TxtResult. AppendText (start. WorkingDirectory + "");
Process p = Process. Start (start );
StreamReader reader = p. StandardOutput; // captures the output stream
String line = reader. ReadLine (); // read a row each time
While (! Reader. EndOfStream)
{
TxtResult. AppendText (line + "");
Line = reader. ReadLine ();
}
P. WaitForExit (); // wait for the program to exit after execution
P. Close (); // Close the process
Reader. Close (); // Close the stream
}