/// <summary>
 /// 编译代码(C语言)
 /// </summary>
 /// <param name="CodeString">要编译的代码字符串</param>
 /// <param name="OutCode">编译代码时候生成的消息(报错消息和成功消息)</param>
 /// <param name="OutPath">输出路径</param>
 /// <param name="projectName">项目名称</param>
 /// <returns>是否编译成功</returns>
 public static bool AnalyTicalCode(string CodeString, out string OutCode, string OutPath, string projectName)
 {
     try
     {
         ///可执行文件的进程
         Process exeprocess;
         string  filename = projectName + ".cpp";
         ///写入文件
         LoggerHelp.WriteMessageToFile(CodeString, filename, OutPath);
         ///执行编译
         exeprocess = Process.Start(CLanguageEditorPath, OutPath + filename + " /Fe:" + OutPath + projectName + ".exe");
         ///等待进程结束
         exeprocess.WaitForExit();
         ///开启编译好的进程
         Process.Start(OutPath + projectName + ".exe");
         OutCode = "Success";
     }
     catch (Exception ex)
     {
         OutCode = ex.Message;
         ///写入错误日志
         LoggerHelp.WriteLogger(ex.ToString());
     }
     return(true);
 }
Пример #2
0
        /// <summary>
        /// 保存生成的代码
        /// </summary>
        public void SaveCode()
        {
            //获取代码
            string[] codes = GetCode();

            if (codes == null || codes.Length <= 0)
            {
                return;
            }
            else
            {
                int i = 0;
                //循环保存代码
                foreach (string code in codes)
                {
                    //写入文件
                    LoggerHelp.WriteMessageToFile(code, "Code" + i++ + ".code", RootPath + _codeFilePath);
                }
            }
        }