• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

c#Winform调用可执行exe文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

c#是一个写windows桌面小工具的好东西,但有个时候,我们需要在 winform 程序中调用其他的 exe 文件,那么该如何实现呢?

如果只是拉起一个 exe 文件,可以参考如下方法实现:

string exefile = "xxx.exe";
if (File.Exists(exefile)) {
    Process process = new Process();
   // params 为 string 类型的参数,多个参数以空格分隔,如果某个参数为空,可以传入”” ProcessStartInfo startInfo
= new ProcessStartInfo(exefile, params); process.StartInfo = startInfo; process.Start(); }

如果不想弹出系统的dos界面,可以参考如下方式实现:

string exefile = "xxx.exe";
if (File.Exists(exefile)) {
    Process process = new Process();
    ProcessStartInfo startInfo = new ProcessStartInfo(exefile, path);
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true; process.StartInfo
= startInfo; process.Start(); process.WaitForExit(2000); string output = process.StandardOutput.ReadToEnd(); rtb_analyze.Text = output; process.Close(); }

当然还有异步方式:

public void exec(string exePath, string parameters)
{
    Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = exePath;
    process.StartInfo.Arguments = parameters;
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.RedirectStandardOutput = true;
    process.Start();
    process.BeginOutputReadLine();
    process.OutputDataReceived += new  DataReceivedEventHandler(processOutputDataReceived);
}

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#使用进程调用bash,不断往bash内插入命令并执行发布时间:2022-07-10
下一篇:
C#中as用法发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap