C# 執行外部命令

wen5 9年前發布 | 3K 次閱讀 C#

///<summary>
 ///executes a system command from inside csharp
 ///</summary>
 ///<param name="cmd">a dos type command like "isql ..."</param>

///<param name ="millsecTimeOut">how long to wait on the command</param>

public static int executeCommand(string cmd, int millsecTimeOut) { System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("CMD.exe", "/C "+cmd); processStartInfo.CreateNoWindow = true; processStartInfo.UseShellExecute = false; System.Diagnostics.Process process = System.Diagnostics.Process.Start(processStartInfo); process.WaitForExit(millsecTimeOut); //wait for 20 sec int exitCode = process.ExitCode; process.Close(); return exitCode; }</pre>

 本文由用戶 wen5 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!