Пример #1
0
        private void Exec(string cmd, string args, string workingDir, Guid sessionGuid, DateTime startTime, string userUID, Course course, Example example)
        {
            var p      = new Process();
            var output = new TestOutput(p, userUID, sessionGuid, course, example, workingDir, startTime);

            lock (_lock)
            {
                _testOutput[sessionGuid] = output;
            }

            p.StartInfo.FileName         = cmd;
            p.StartInfo.Arguments        = args;
            p.StartInfo.WorkingDirectory = workingDir;
            p.StartInfo.UseShellExecute  = false;

            p.EnableRaisingEvents = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.OutputDataReceived += (s, e) => { lock (_lock) output.Output.AppendLine(e.Data); };
            p.ErrorDataReceived  += (s, e) => { lock (_lock) output.Output.AppendLine(e.Data); };
            p.Exited             += (s, e) =>
            {
                _log.InfoFormat("Process \"{0} {1}\" exited with error code {2}", cmd, args, p.ExitCode);
                output.Finish();
                _saveService.Save(output);
                p.Dispose();
            };

            p.Start();
            p.BeginErrorReadLine();
            p.BeginOutputReadLine();
            p.WaitForExit(1);
        }