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

最佳答案

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

关于c# - 如何在 C# 中调用批处理文件(.bat)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2996777/

10-13 06:26