C# 调用可执行exe文件几种方法小结
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
1.利用进程池方式启动1. string exefile = "xxx.exe"; 2. if (File.Exists(exefile)) { 3. Process process = new Process(); // params 为 string 类型的参数,多个参数以空格分隔,如果某个参数为空,可以传入”” 4. ProcessStartInfo startInfo = new ProcessStartInfo(exefile, params); 5. process.StartInfo = startInfo; 6. process.Start(); 7. } 2.遮蔽CLI启动窗口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.异步启动方式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 编辑过 |
关键字查询
相关文章
正在查询... |