• C# 中运行exe程序


     private int runProcess(string fileName, string appParam)
            {
                int returnValue = -1;
                try
                {
                    Process myProcess = new Process();
                    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, appParam);
                    myProcessStartInfo.CreateNoWindow = true;
                    myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    myProcess.StartInfo = myProcessStartInfo;
                    myProcess.Start();
    
                    while (!myProcess.HasExited)
                    {
                        myProcess.WaitForExit();
                    }
    
                    returnValue = myProcess.ExitCode;
                    myProcess.Dispose();
                    myProcess.Close();
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                return returnValue;
            }
    

     1、启动*.exe程序

     
      System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.Arguments = String.Format("{0} {1} {2}", columnStr, tempFilePath, "True"); startInfo.FileName = this.applicationPath + "\Excel.exe"; startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = startInfo;
       process.Start();   
       process.WaitForExit(); process.Close();

     2、调用外部程序

            private void CallOutProcess(string s文件名)
            {
                System.Diagnostics.ProcessStartInfo pinfo = new System.Diagnostics.ProcessStartInfo();
                pinfo.UseShellExecute = true;
                pinfo.FileName = s文件名;
                //启动进程
                System.Diagnostics.Process p = System.Diagnostics.Process.Start(pinfo);
            }
    
  • 相关阅读:
    NPM 重新回炉
    构建工具
    工作的环境部署
    Proxy 代理
    Promise 的 用法及实现
    JS 的 继承
    动态规划——LCS
    矩阵连乘——动态规划
    线段树&树状数组
    SpringAOP
  • 原文地址:https://www.cnblogs.com/shenchao/p/3556466.html
Copyright © 2020-2023  润新知