Example 1.

Running a command line application, without concern for the results:

private void Run(){
    System.Diagnostics.Process.Start(@”C:\runFile.bat”);
}

Example 2.

Retrieving the results and waiting until the process stops (running the process synchronously):

private void Run(){
    System.Diagnostics.ProcessStartInfo psi =
   
new System.Diagnostics.ProcessStartInfo(@”C:\listfiles.bat”);
    psi.RedirectStandardOutput =
true;
    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    psi.UseShellExecute =
false;
    System.Diagnostics.Process listFiles;
    listFiles = System.Diagnostics.Process.Start(psi);
    System.IO.StreamReader myOutput = listFiles.StandardOutput;
    listFiles.WaitForExit(2000);
    if (listFiles.HasExited){
      string
output = myOutput.ReadToEnd();
      this.processResults.Text = output;
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here