如何在c#中调用批处理文件(.bat)?
答案 0 :(得分:8)
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("path to batch file");