Welcome to Comunidade Bloggers |create|it| Sign in | Join | Help

Raúl Ribeiro

Windows SharePoint Services 3.0 , .net, Microsoft Office SharePoint 2007, Office 2007 and 2010

News

How to run another application or batch file from my Visual C# .NET code

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;
    }
}

Posted: Monday, June 20, 2005 4:41 PM by rrr
Filed under: ,

Comments

No Comments

Anonymous comments are disabled