Copy codeThe Code is as follows: using System;
Using System. Collections;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Diagnostics;
Namespace WebForm
{
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Response. Write (ExeCommand ("ping www.126.com "));
}
Public string ExeCommand (string commandText)
{
Process p = new Process ();
P. StartInfo. FileName = "cmd.exe ";
P. StartInfo. UseShellExecute = false;
P. StartInfo. RedirectStandardInput = true;
P. StartInfo. RedirectStandardOutput = true;
P. StartInfo. RedirectStandardError = true;
P. StartInfo. CreateNoWindow = true;
String strOutput = null;
Try
{
P. Start ();
P. StandardInput. WriteLine (commandText );
P. StandardInput. WriteLine ("exit ");
StrOutput = p. StandardOutput. ReadToEnd ();
P. WaitForExit ();
P. Close ();
}
Catch (Exception e)
{
StrOutput = e. Message;
}
Return strOutput;
}
}
}