Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Selectively capturing console output in C#

By: kruncher on Feb 10th, 2013  |  syntax: C#  |  size: 0.38 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Keep track of the original output writer
  2. TextWriter originalOut = Console.Out;
  3.  
  4. // Override console output with a custom one
  5. StringWriter buf = new StringWriter();
  6. Console.SetOut(buf);
  7.  
  8. Console.WriteLine("This will be captured!");
  9.  
  10. // Capture output!
  11. buf.Flush();
  12. string capturedOutput = buf.ToString();
  13.  
  14. // Restore original output writer
  15. Console.SetOut(originalOut);