Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Keep track of the original output writer
- TextWriter originalOut = Console.Out;
- // Override console output with a custom one
- StringWriter buf = new StringWriter();
- Console.SetOut(buf);
- Console.WriteLine("This will be captured!");
- // Capture output!
- buf.Flush();
- string capturedOutput = buf.ToString();
- // Restore original output writer
- Console.SetOut(originalOut);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement