c#调用exe MFC文件报错,单独运行exe文件不报错

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!

Program: ...ware_demo_c++_2021-09-25\PCSoftware_demo\Debug\PCSoftware.exe
File: minkernel\crts\ucrt\src\appcrt\stdio\fgets.cpp
Line: 33

Expression: stream.valid()

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

---------------------------
中止(A) 重试(R) 忽略(I)
---------------------------

问题在MFC程序本身:fgets.cpp与读取文件事件有关,exe在启动时读文件导致,可以屏蔽读取文件事件,再测试。

 static public void StartLightSourceEqu(string exe_path)
        {
            //ProcessStartInfo info = new ProcessStartInfo();
            //info.FileName = exe_path;
            //info.Arguments = "";
            //info.WindowStyle = ProcessWindowStyle.Minimized;
            //Process pro = Process.Start(info);
            //pro.WaitForExit();


            string exefile = exe_path;
            if (File.Exists(exefile))
            {
                Process process = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo(exefile);
                startInfo.UseShellExecute = false;
                startInfo.RedirectStandardOutput = false; 
                startInfo.CreateNoWindow = true;
                process.StartInfo = startInfo;
                process.Start();
               // process.WaitForExit(2000);
               // string output = process.StandardOutput.ReadToEnd();
              //  rtb_analyze.Text = output;
                process.Close();
            }
        }

 

posted @ 2023-07-04 14:06  txwtech  阅读(134)  评论(0编辑  收藏  举报