C#执行外部命令的方法
程序员文章站
2023-12-04 17:33:34
本文实例讲述了c#执行外部命令的方法。分享给大家供大家参考。具体实现方法如下:
///
///executes a system...
本文实例讲述了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; }
希望本文所述对大家的c#程序设计有所帮助。