public void Start() { if (_process == null) { throw new Exception("Can't reuse disposed job"); } _process.OutputDataReceived += (_, e) => { // e.Data is null to signal end of stream if (e.Data != null) { _standardOutput.Enqueue(e.Data); OnStandardOutput?.Invoke(e.Data); OutputBuilder.AppendLine(e.Data); } }; _process.ErrorDataReceived += (_, e) => { // e.Data is null to signal end of stream if (e.Data != null) { _standardError.Enqueue(e.Data); OnStandardError?.Invoke(e.Data); ErrorBuilder.AppendLine(e.Data); } }; StartTimeUtc = DateTime.UtcNow; _process.Start(); _process.BeginOutputReadLine(); _process.BeginErrorReadLine(); }
/// <summary> /// This must be called AFTER <see cref="Start"/> /// </summary> private void BindEventHandlers() { if (!Conf.ShowTerminal) { Proc.BeginOutputReadLine(); Proc.BeginErrorReadLine(); Proc.ErrorDataReceived += (sender, args) => { OnStandardError?.Invoke(args.Data); Log.DebugFormat("stderr: {0}", args.Data); }; Proc.OutputDataReceived += (sender, args) => { OnStandardOut?.Invoke(args.Data); Log.DebugFormat("stdout: {0}", args.Data); }; } Proc.Exited += delegate { Log.Info("exited: " + Proc.ExitCode); AtExit?.Invoke(this); }; }