How can I call a batch file(.bat) in c#?
How c开发者_如何转开发an I call a batch file(.bat) in c#?
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;
}
Use Process.Start("cmd.exe", pathToBat);
.
Use Process.Start
:
Process.Start("path to batch file");
精彩评论