Copy Code code 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;
}
}
}