现在的位置: 首页 > 移动开发 > 正文

怎样用C#ASP.NET执行BAT批处理代码

2020年06月03日 移动开发 ⁄ 共 1206字 ⁄ 字号 评论关闭

  每次出现类似问题总要用远程服务器或者进入机房操作机器,但有时是晚上不是很方便,但远程的密码和机房钥匙又不方便给他人,因此想到以下解决方法。下面学步园小编来讲解下怎样用C#ASP.NET执行BAT批处理代码?

  怎样用C#ASP.NET执行BAT批处理代码

  usingSystem;

  usingSystem.Collections.Generic;

  usingSystem.Web;

  usingSystem.Web.UI;

  usingSystem.Web.UI.WebControls;

  namespaceWebApplication3

  {

  publicpartialclass_Default:System.Web.UI.Page

  {

  protectedvoidPage_Load(objectsender,EventArgse)

  {

  }

  怎样用C#ASP.NET执行BAT批处理代码

  protectedvoidButton1_Click(objectsender,EventArgse)

  {

  System.Diagnostics.ProcessStartInfopro=newSystem.Diagnostics.ProcessStartInfo("cmd.exe");

  pro.UseShellExecute=false;

  pro.RedirectStandardOutput=true;

  pro.RedirectStandardError=true;

  pro.Arguments="/KD:\\jiamiError\\test.bat";

  pro.WorkingDirectory="D:\\jiamiError\\";

  System.Diagnostics.Processproc=System.Diagnostics.Process.Start(pro);

  System.IO.StreamReadersOut=proc.StandardOutput;

  proc.Close();

  stringresults=sOut.ReadToEnd()。Trim();

  sOut.Close();

  stringfmtStdOut="{0}";

  this.Response.Write(String.Format(fmtStdOut,results.Replace(System.Environment.NewLine,"
")));

  /*Response.Write("");*/

  /*Response.Redirect("Success.html");*/

  }

  }

  }

  以上就是关于“怎样用C#ASP.NET执行BAT批处理代码”的内容,希望对大家有用。更多资讯请关注学步园。学步园,您学习IT技术的优质平台!

抱歉!评论已关闭.