日期:2014-05-18  浏览次数:21115 次

C# Winform 里用 process如何判断BAT文件运行结束?有代码
从网上看到的代码如下, 但是不知道如何取调用它,然后利用它的返回值判断BAT文件已经结束运行。 另外 psi.Arguments = arguments 这个东东怎么用的, 我需要改吗?

public string RunBAT(string epath, string arguments) //让 MASS-DELETE运行状态显示出来
  {
  System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
  psi.FileName = "C:\\Run.BAT";
  psi.UseShellExecute = true;
  psi.Arguments = arguments;
  psi.CreateNoWindow = false;
  psi.RedirectStandardOutput = true;
  string s = "";
  System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
  while (p.WaitForExit(0) == false)
  {
  s += p.StandardOutput.ReadLine() + "\r\n";
  }
  return s;

------解决方案--------------------
bat文件里没有中断或者等待输入的话,执行完这个进程也就结束了,不需要再改什么。

没有参数的话就去掉好了。