2010-06-08 65 views

回答

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

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

相關問題