zoukankan      html  css  js  c++  java
  • c# Winform 调用可执行 exe 文件

    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);
    }
  • 相关阅读:
    linux查看硬件信息的方法
    linux最常用命令
    研究php单例模式实现数据库类
    HTML5语义元素
    第一次博客作业
    2020系统综合实践 第7次实践作业 06组
    2020系统综合实践 第6次实践作业 06组
    2020系统综合实践 第5次实践作业
    2020系统综合实践 第4次实践作业
    2020系统综合实践 第3次实践作业
  • 原文地址:https://www.cnblogs.com/xsbx/p/winform.html
Copyright © 2011-2022 走看看