tags:

views:

67

answers:

3

Hi guys,

How can I call a batch file(.bat) in c sharp?

Great thanks.

+4  A: 

Use Process.Start:

Process.Start("path to batch file");
Oded
+4  A: 

Use Process.Start("cmd.exe", pathToBat);.

Femaref
+7  A: 

See Execute Commands From C#

public static int ExecuteCommand(string Command, int Timeout)
{
    int exitCode;
    var processInfo = new ProcessStartInfo("cmd.exe", "/C " + Command);
    processInfo.CreateNoWindow = true;
    processInfo.UseShellExecute = false;
    Process process = Process.Start(processInfo);
    process.WaitForExit(Timeout);
    exitCode = process.ExitCode;
    process.Close();
    return exitCode;
}
RedFilter