C# 調(diào)用可執(zhí)行exe文件幾種方法小結(jié)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
1.利用進(jìn)程池方式啟動(dòng)1. string exefile = "xxx.exe"; 2. if (File.Exists(exefile)) { 3. Process process = new Process(); // params 為 string 類(lèi)型的參數(shù),多個(gè)參數(shù)以空格分隔,如果某個(gè)參數(shù)為空,可以傳入”” 4. ProcessStartInfo startInfo = new ProcessStartInfo(exefile, params); 5. process.StartInfo = startInfo; 6. process.Start(); 7. } 2.遮蔽CLI啟動(dòng)窗口1. string exefile = "xxx.exe"; 2. if (File.Exists(exefile)) { 3. Process process = new Process(); 4. ProcessStartInfo startInfo = new ProcessStartInfo(exefile, path); 5. startInfo.UseShellExecute = false; 6. startInfo.RedirectStandardOutput = true; startInfo.CreateNoWindow = true; 7. process.StartInfo = startInfo; 8. process.Start(); 9. process.WaitForExit(2000); 10. string output = process.StandardOutput.ReadToEnd(); 11. rtb_analyze.Text = output; 12. process.Close(); 13.} 3.異步啟動(dòng)方式1. public void exec(string exePath, string parameters) 2. { 3. Process process = new System.Diagnostics.Process(); 4. process.StartInfo.FileName = exePath; 5. process.StartInfo.Arguments = parameters; 6. process.StartInfo.UseShellExecute = false; 7. process.StartInfo.CreateNoWindow = true; 8. process.StartInfo.RedirectStandardOutput = true; 9. process.Start(); 10. process.BeginOutputReadLine(); 11. process.OutputDataReceived += new DataReceivedEventHandler(processOutputDataReceived); 12.} 該文章在 2024/1/19 11:07:04 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |