/// <summary> /// Logs the process StdOut and StdErr to the destination, then clears both output buffers. /// </summary> /// <param name="logger">The logger to write to.</param> /// <param name="output">The <see cref="IProcessOutput"/> to write.</param> public static void LogAndClear(this ILogger logger, IProcessOutput output) { string name = $"{output.ProcessStartInfo.FileName} {output.ProcessStartInfo.Arguments}, working directory {output.ProcessStartInfo.WorkingDirectory}"; logger.LogInformation("StdOut for process {Name}: {StdOut}", name, output.StandardOutputText); string stdErr = output.StandardErrorText; if (!string.IsNullOrEmpty(stdErr)) { logger.LogWarning("StdErr for process {Name}: {StdErr}", name, stdErr); } output.ClearAllOutput(); }
/// <summary> /// Writes the process StdOut and StdErr to the console, then clears both output buffers. /// </summary> /// <param name="output">The <see cref="IProcessOutput"/> to write.</param> public static void WriteToConsoleAndClear(this IProcessOutput output) { string name = $"{output.ProcessStartInfo.FileName} {output.ProcessStartInfo.Arguments}, working directory {output.ProcessStartInfo.WorkingDirectory}"; Console.WriteLine($"\nStdOut for process {name}:"); Console.WriteLine(output.StandardOutputText); Console.WriteLine(); string stdErr = output.StandardErrorText; if (!string.IsNullOrEmpty(stdErr)) { Console.WriteLine($"\nStdErr for process {name}:"); Console.WriteLine(stdErr); Console.WriteLine(); } output.ClearAllOutput(); }