Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the command line, or run a batch file from managed code? (.NET)

Just like the subject states. I want to be able to run iisreset, batch files, etc. from the a console application. Can I/How do I do it?

like image 811
Kyle West Avatar asked Feb 02 '09 04:02

Kyle West


3 Answers

That's quite possible, for example:

 System.Diagnostics.Process.Start(@"C:\listfiles.bat");
like image 127
Otávio Décio Avatar answered Sep 19 '22 16:09

Otávio Décio


Check this example from C# Station

using System;
using System.Diagnostics;

namespace csharp_station.howto
{
    /// <summary>
    /// Demonstrates how to start another program from C#
    /// </summary>
    class ProcessStart
    {
        static void Main(string[] args)
        {
            Process notePad = new Process();

            notePad.StartInfo.FileName   = "notepad.exe";
            notePad.StartInfo.Arguments = "ProcessStart.cs";

            notePad.Start();
        }
    }
}
like image 24
Ric Tokyo Avatar answered Sep 22 '22 16:09

Ric Tokyo


You can also do this:

  System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
  info.UseShellExecute = true;
  info.FileName = "iisreset";
  System.Diagnostics.Process.Start(info);



  Console.ReadLine();
like image 45
Dimi Takis Avatar answered Sep 18 '22 16:09

Dimi Takis