How To: Execute command line in C#, get STD OUT results

后端 未结 17 1241
既然无缘
既然无缘 2020-11-21 13:12

How do I execute a command-line program from C# and get back the STD OUT results? Specifically, I want to execute DIFF on two files that are programmatically selected and wr

17条回答
  •  感动是毒
    2020-11-21 13:46

     System.Diagnostics.ProcessStartInfo psi =
       new System.Diagnostics.ProcessStartInfo(@"program_to_call.exe");
     psi.RedirectStandardOutput = true;
     psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
     psi.UseShellExecute = false;
     System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi); ////
     System.IO.StreamReader myOutput = proc.StandardOutput;
     proc.WaitForExit(2000);
     if (proc.HasExited)
      {
          string output = myOutput.ReadToEnd();
     }
    

提交回复
热议问题