private int ExecuteTask(Task task) { string name = "Task"; if (task.ProducedFiles != null && task.ProducedFiles.Count != 0) { name = Path.GetFileName(task.ProducedFiles[0]); } var profilerEvent = Profiling.Begin(name); var startInfo = new ProcessStartInfo { WorkingDirectory = task.WorkingDirectory, FileName = task.CommandPath, Arguments = task.CommandArguments, UseShellExecute = false, RedirectStandardInput = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, }; if (Configuration.Verbose) { lock (_locker) { Log.Verbose(""); Log.Verbose(task.CommandPath); Log.Verbose(task.CommandArguments); Log.Verbose(""); } } if (task.InfoMessage != null) { Log.Info(task.InfoMessage); } Process process = null; try { try { process = new Process(); process.StartInfo = startInfo; process.OutputDataReceived += ProcessDebugOutput; process.ErrorDataReceived += ProcessDebugOutput; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); } catch (Exception ex) { Log.Error("Failed to start local process for task"); Log.Exception(ex); return(-1); } // Hang until process end process.WaitForExit(); Profiling.End(profilerEvent); return(process.ExitCode); } finally { Profiling.End(profilerEvent); // Ensure to cleanup data process?.Close(); } }