小言_互联网的博客

调用外部exe

403人阅读  评论(0)

                      try
                            {  //杀死lis进程
                                Process[] process = Process.GetProcesses();
                                foreach (Process prc in process)
                                {
                                    
                                    if (prc.ProcessName == "CC" || prc.ProcessName == "NeuLis.Interface.PrintBarcode.Components")
                                    {
                                        prc.Kill();
                                        break;
                                    }
                                        
                                }
                                //配置路径参数//改为获取程序启动路径
                                string strStartPath = System.Windows.Forms.Application.StartupPath;
                                string loaclDataFilePath = strStartPath + @"\neusoftlis";
                                string exePath1 = loaclDataFilePath + @"\NeuLisFTP.exe";
                                string exePath2 = loaclDataFilePath + @"\NeuLis.Interface.PrintBarcode.Components.exe";
                                string Filepath = @"D:\MZ\";
                                if (!Directory.Exists(Filepath))
                                {
                                    Directory.CreateDirectory(Filepath);
                                }
                                string exeArgs = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", "6699", "刘平", "1202", "手术室", "1202", "手术室", "N", "住院", "01", "总院");
                                string exeArgs2 = string.Format("{0}", Filepath);
                                StarExe(exePath1, exeArgs, p1);//登录
                                StarExe(exePath2, exeArgs2, p2);//登录   
                                //先删除文件
                                string strFilePath = @"D:\MZ\PrintInfo.txt";
                                do
                                {
                                    DeleteFile(strFilePath);
                                    //写入文件                           
                                    string filename = @"PrintInfo.txt";
                                    string filecontent = string.Format("{0};{1};{2}", this.patientInfo.PatientBasicInfoDto.Mrn, "super", "dd");
                                    WriteFile(Filepath, filename, filecontent);
                                    System.Threading.Thread.Sleep(1000);
                                } while (File.Exists(strFilePath));
                            }
                            catch (Exception ee)
                            {
                                MessageBox.Show("调用LISEXE失败:" + ee);
                            }

        /// <summary>
        /// 删除文件或者文件夹
        /// </summary>
        /// <param name="fileFullPath">文件夹或文件路径</param>
        public void DeleteFile(string fileFullPath)
        {
            if (File.Exists(fileFullPath))
            {
                // 2、根据路径字符串判断是文件还是文件夹
                FileAttributes attr = File.GetAttributes(fileFullPath);
                // 3、根据具体类型进行删除
                if (attr == FileAttributes.Directory)
                {
                    // 3.1、删除文件夹
                    Directory.Delete(fileFullPath, true);
                }
                else
                {
                    // 3.2、删除文件
                    File.Delete(fileFullPath);
                }
                File.Delete(fileFullPath);
            }
        }

        /// <summary>
        /// 写入文件
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="name">文件名称</param>
        /// <param name="info">信息</param>
        public void WriteFile(string path, string name, string info)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            StreamWriter sw;
            FileInfo fi = new FileInfo(path + "/" + name);
            sw = fi.CreateText();
            sw.WriteLine(info, Encoding.UTF8);
            sw.Close();
            sw.Dispose();

        }

 

        /// <summary>
        /// 调用外部EXE
        /// </summary>
        /// <param name="exeStartPath"></param>
        /// <param name="args"></param>
        /// <param name="p"></param>
        public void StarExe(string exeStartPath, string args, System.Diagnostics.Process p)
        {
            //System.Diagnostics.Process p = new System.Diagnostics.Process();
            //if (p == null)
            //{
            //

            p = new System.Diagnostics.Process();
            p.StartInfo.FileName = exeStartPath;
            if (!string.IsNullOrEmpty(args))
            {
                p.StartInfo.Arguments = args;//启动参数 
            }

            p.Start(); 
            //}
            //else
            //{
            //    if (p.HasExited) //是否正在运行
            //    {
            //        p.Kill();
            //    }
            //}
        }


转载:https://blog.csdn.net/qq_41515170/article/details/101452871
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场