ASP.Net執(zhí)行cmd命令的實現(xiàn)代碼
更新時間:2011年02月19日 19:16:24 作者:
ASP.Net執(zhí)行cmd命令的實現(xiàn)代碼,需要的朋友可以參考下。
復制代碼 代碼如下:
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;
}
}
}
相關(guān)文章
詳解可跨域的單點登錄(SSO)實現(xiàn)方案【附.net代碼】
本篇文章主要介紹了可跨域的單點登錄(SSO)實現(xiàn)方案,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
.Net?Core3.0?WebApi?項目框架搭建之使用Serilog替換掉Log4j
Serilog 是一個用于.NET應用程序的日志記錄開源庫,配置簡單,接口干凈,并可運行在最新的.NET平臺上,這篇文章主要介紹了.Net?Core3.0?WebApi?項目框架搭建之使用Serilog替換掉Log4j,需要的朋友可以參考下2022-02-02
.NET?6開發(fā)TodoList應用引入第三方日志庫
這篇文章主要介紹了.NET?6開發(fā)TodoList應用引入第三方日志庫,在我們項目開發(fā)的過程中,使用.NET?6自帶的日志系統(tǒng)有時是不能滿足實際需求的,比如有的時候我們需要將日志輸出到第三方平臺,更多詳細內(nèi)容請需要的小伙伴參考下面文章內(nèi)容2021-12-12
Entity?Framework管理一對二實體關(guān)系
本文詳細講解了Entity?Framework管理一對二實體關(guān)系的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03
如何將數(shù)據(jù)綁到gridview然后導成excel
這篇文章主要介紹了如何將數(shù)據(jù)綁到gridview然后導成excel,需要的朋友可以參考下2014-02-02

