[轉貼] asp.net 執行Server上的EXE執行檔
********************************************************************************** asp.net_執行Server上的EXE執行檔 依照前篇的敘述,第二個要處理的問題是,如何利用asp.net呼叫Server上的exe執行。 如果查網路資料,會查到很多一模一樣的文章,基本上有兩種方式: 1. 利用ShellExecute來處理。 引用: using System.Runtime.InteropServices; 宣告: [DllImport("shell32.dll")] private static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, Int32 nShowCmd); 程式碼: string Dir = page.Server.MapPath("~/"); string CmdStr = Dir + "geoidint.exe"; ShellExecute(IntPtr.Zero, "open", CmdStr, "-I" + Dir + "input.txt -G" + Dir + "output.txt", null, 1); 比較需要注意的地方是,如果你跟我一樣需要傳入參數,就在ShellExecute的第四個參數傳入;又如果傳入的參數是檔案路徑,就要看你所執行的EXE檔是怎麼抓的,像我必須傳入完整路徑,所以參數的部分採組合字串的方式。 2. 利用System.Diagnostics.Process來處理。 引用: using System.Diagnostics; 程式碼: Process process = new Process(); process.StartInfo.FileName = Dir + "geoidint.exe"; process.StartInfo.Arguments = "-I...