当前位置:编程学习 > C#/ASP.NET >>

C# 执行批处理文件


//   System.Diagnostics.Process pr1 = System.Diagnostics.Process.Start("cmd", " /c ftpget.bat");
//   pr1.StartInfo.CreateNoWindow = true;
//   pr1.WaitForExit(); 
   System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");

   psi.UseShellExecute = false;

   psi.RedirectStandardOutput = true;

   //psi.RedirectStandardInput = true;

   psi.RedirectStandardError = true;

   psi.Arguments = "/c F:\aa\ftpget.bat";

   psi.WorkingDirectory = "F:\aa\";

 

   // Start the process

   System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);

   // Attach the output for reading

   System.IO.StreamReader sOut = proc.StandardOutput;

   proc.Close();

 

   // Read the sOut to a string.

   string results = sOut.ReadToEnd().Trim();

   sOut.Close();
   Console.WriteLine(results);

补充:asp.net教程,.Net开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,