tags:

views:

123

answers:

3

How can I redirect whatever is written to the console to be written into a string?

+1  A: 
string consoleString = Console.ReadLine();
Kevin Crowell
+3  A: 

Use Console.SetOut ();

Sorantis
+13  A: 

For your own process, Console.SetOut and redirect it to a TextWriter built on top of a string builder or memory stream. For a launched child process, use ProcessStartInfo.RedirectStandardOutput when launching the process.

Remus Rusanu