Just a learner
Just a learner

Reputation: 28572

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

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

Upvotes: 3

Views: 2834

Answers (3)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171411

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

Upvotes: 8

Femaref
Femaref

Reputation: 61437

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

Upvotes: 5

Oded
Oded

Reputation: 498992

Use Process.Start:

Process.Start("path to batch file");

Upvotes: 4

Related Questions