专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

c#调用exe捕获返回值

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 0:29:28       共计:3624 浏览
c#源码例子如下:
调用方法:
string baseName = System.IO.Directory.GetCurrentDirectory();
            // baseName+"/"
            // string fileName = @"C:\Users\59930\Desktop\20170605\WindowsFormsApp1\WindowsFormsApp1\WindowsFormsApp1\bin\x86\Debug\WindowsFormsApp1.exe";
            string fileName = baseName + @"\CardRead.exe";
            string para = "1.exe " + code;
          
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = fileName;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = para;//参数以空格分隔,如果某个参数为空,可以传入””  
            p.Start();
            p.WaitForExit();
            string output = p.StandardOutput.ReadToEnd();



调用的exe 返回值中写
Console.Write(mmma);



 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;
        }

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:SQLServer 日期函数大全 | ·下一条:C#Process执行批处理后如何获取返回值?

Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有