c#调用exe捕获返回值

c#源码例子如下:

 private void ProgressCheck(object sender, EventArgs e)
        {
            string strCheck = System.Environment.CurrentDirectory + "\\ProgressCheck\\ProgressCheck.exe";
            string TaskPollExePath = System.Environment.CurrentDirectory + "\\TaskPoll.exe";
            string CreFusXmlExePath = System.Environment.CurrentDirectory + "\\CreFusXml.exe";
            string CoordConvertTaskExePath = System.Environment.CurrentDirectory + "\\CoordCvt\\CoordConvertTask.exe";
            string GCSConvertExePath = System.Environment.CurrentDirectory + "\\CoordCvt\\GCSConvert.exe";
            string CreFusCheckPrjExePath = System.Environment.CurrentDirectory + "\\FusCheck\\CreFusCheckPrj.exe";
            string ProTskExePath = System.Environment.CurrentDirectory + "\\FusCheck\\TskExe\\ProTsk.exe";
            string MDomSupQuaChkExePath = System.Environment.CurrentDirectory + "\\FusCheck\\KnlExe\\MDomSupQuaChk.exe";

            Process process1 = CreateProcessTasks(strCheck, TaskPollExePath, true);
            process1.Start();
            process1.WaitForExit();
            if (process1.ExitCode!= 0)
            {
                MessageBox.Show(TaskPollExePath, "程序异常");
                return;
            }

            Process process2 = CreateProcessTasks(strCheck, CreFusXmlExePath, true);
            process2.Start();
            process2.WaitForExit();
            if (process2.ExitCode != 0)
            {
                MessageBox.Show(CreFusXmlExePath, "程序异常");
                return;
            }

            Process process3 = CreateProcessTasks(strCheck, CoordConvertTaskExePath, true);
            process3.Start();
            process3.WaitForExit();
            if (process3.ExitCode != 0)
            {
                MessageBox.Show(CoordConvertTaskExePath, "程序异常");
                return;
            }

            Process process4 = CreateProcessTasks(strCheck, GCSConvertExePath, true);
            process4.Start();
            process4.WaitForExit();
            if (process4.ExitCode != 0)
            {
                MessageBox.Show(GCSConvertExePath, "程序异常");
                return;
            }

            Process process5 = CreateProcessTasks(strCheck, CreFusCheckPrjExePath, true);
            process5.Start();
            process5.WaitForExit();
            if (process5.ExitCode != 0)
            {
                MessageBox.Show(CreFusCheckPrjExePath, "程序异常");
                return;
            }

            Process process6 = CreateProcessTasks(strCheck, ProTskExePath, true);
            process6.Start();
            process6.WaitForExit();
            if (process6.ExitCode != 0)
            {
                MessageBox.Show(ProTskExePath, "程序异常");
                return;
            }

            Process process7 = CreateProcessTasks(strCheck, MDomSupQuaChkExePath, true);
            process7.Start();
            process7.WaitForExit();
            if (process7.ExitCode != 0)
            {
                MessageBox.Show(MDomSupQuaChkExePath, "程序异常");
                return;
            }

            MessageBox.Show("程序无异常","提示");
            return;
        }

        private Process CreateProcessTasks(string exe_path, string str_arguments, bool b_create_win = true)
        {
            Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = exe_path;
            process.StartInfo.Arguments = str_arguments;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = false;  //true
            process.StartInfo.RedirectStandardOutput = false;  //true
            process.StartInfo.RedirectStandardError = false;
            process.StartInfo.CreateNoWindow = b_create_win;
            //process.Start();
            return process;
        }

猜你喜欢

转载自blog.csdn.net/u013230291/article/details/80615828