-
-
Save davidalpert/efe3c64dbb82d59e951c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RedirectedConsole : IDisposable | |
{ | |
readonly TextWriter outBefore; | |
readonly TextWriter errBefore; | |
readonly StringWriter console; | |
public RedirectedConsole() | |
{ | |
console = new StringWriter(); | |
outBefore = Console.Out; | |
errBefore = Console.Error; | |
Console.SetOut(console); | |
Console.SetError(console); | |
} | |
public string Output | |
{ | |
get { return console.ToString(); } | |
} | |
public void Dispose() | |
{ | |
Console.SetOut(outBefore); | |
Console.SetError(errBefore); | |
console.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment