public static ProcessManager.ProcessState MonitorProcessOutput(this ReactiveProcess process) { Contract.Requires<ArgumentNullException>(process != null); var state = new ProcessManager.ProcessState(); if (!process.StartInfo.RedirectStandardOutput) throw new InvalidOperationException("Not redirected output"); if (!process.StartInfo.RedirectStandardError) throw new InvalidOperationException("Not redirected error"); process.StandardOutputObservable.Subscribe(() => state.UpdateStamp()); process.StandardErrorObservable.Subscribe(() => state.UpdateStamp()); return state; }
public static ProcessManager.ProcessState MonitorProcessOutput(this Process process) { Contract.Requires<ArgumentNullException>(process != null); var state = new ProcessManager.ProcessState(); if (!process.StartInfo.RedirectStandardOutput) throw new InvalidOperationException("Not redirected output"); if (!process.StartInfo.RedirectStandardError) throw new InvalidOperationException("Not redirected error"); process.OutputDataReceived += (sender, args) => state.UpdateStamp(); process.ErrorDataReceived += (sender, args) => state.UpdateStamp(); return state; }