/// <summary> /// Runs program and returns output to properties /// </summary> public async System.Threading.Tasks.Task Run() { try { if (_copyfrom != null & _copyto != null) { await Copy(); } StartInfo.FileName = (_path + _filename); StartInfo.Arguments = _arguments; Log(log.Debug, "Filename:{0}", StartInfo.FileName); Log(log.Debug, "Arguments:{0}", StartInfo.Arguments); var pProcess = System.Diagnostics.Process.Start(StartInfo); StandardOutput = await pProcess.StandardOutput.ReadToEndAsync(); StandardError = await pProcess.StandardError.ReadToEndAsync(); //pProcess.WaitForExit(); ExitCode = pProcess.ExitCode; Log(log.Debug, "ExitCode: " + ExitCode.ToString()); ManageOutput(); Log(log.Debug, "StandardOutput: " + StandardOutput.Replace("\r", " ").Replace("\n", " ")); Log(log.Debug, "StandardError: " + StandardError.Replace("\r", " ").Replace("\n", " ")); RaiseExecuted(); } catch (Exception e) { Log(log.Error, e.ToString()); } }
/// <summary> /// 编译 /// </summary> /// <param name="ans">要编译的代码</param> /// <param name="identify">程序标识符</param> /// <returns>是否编译成功</returns> public bool Compile(string ans, Guid identify) { var file_name = identify.ToString("D"); var file = new FileStream(file_name + ".cpp", FileMode.CreateNew); byte[] grp = Encoding.ASCII.GetBytes(ans); file.Write(grp, 0, grp.Length); file.Close(); var ret = Compile(file_name + ".cpp"); StandardError = StandardError .Replace(file_name, "main") .Replace(MasterPath, GetType().Name); StandardOutput = StandardOutput .Replace(file_name, "main") .Replace(MasterPath, GetType().Name); return(ret); }