C#執(zhí)行外部命令的方法
更新時間:2015年06月29日 15:35:00 作者:pythoner
這篇文章主要介紹了C#執(zhí)行外部命令的方法,實例分析了C#調(diào)用CMD.exe程序執(zhí)行外部命令的技巧,需要的朋友可以參考下
本文實例講述了C#執(zhí)行外部命令的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
///<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; }
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C# 設(shè)置防火墻的創(chuàng)建規(guī)則
這篇文章主要介紹了C# 設(shè)置防火墻的創(chuàng)建規(guī)則,幫助大家更好的利用c#操作防火墻,感興趣的朋友可以了解下2020-11-11

C#使用TensorFlow.NET訓(xùn)練自己的數(shù)據(jù)集的方法
這篇文章主要介紹了C#使用TensorFlow.NET訓(xùn)練自己的數(shù)據(jù)集的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
2020-03-03