如何在c#中调用批处理文件(.bat)?

时间:2010-06-08 11:17:31

标签: c# batch-file

如何在c#中调用批处理文件(.bat)?

3 个答案:

答案 0 :(得分:8)

请参阅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;
}

答案 1 :(得分:5)

使用Process.Start("cmd.exe", pathToBat);

答案 2 :(得分:4)

使用Process.Start

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