C# Copy stream to Console

Date: 2021-06-04
// ignore other console output
Console.SetOut(TextWriter.Null);
Console.Write("this text gets lost")
// create any stream
using (var stream = File.Open("image.png"))
{
	// get the STDOUT stream 
	var consoleStream = Console.OpenStandardOutput();
	stream.Position = 0; // reset position to read all data
	stream.CopyTo(consoleStream);
	consoleStream.Flush();
}
51010cookie-checkC# Copy stream to Console