Get all the console buffer

Asked

Viewed 92 times

0

How can I get all the Console text (System.Console) for a String, without redirecting the console output to a process, for example, I want to get what’s in the Console through the Console itself. Is that possible? If so, how do I do this?

  • But from a console other than your application? Being your application wouldn’t it be just saving the strings that are sent to the screen? I don’t think I understand, you can give a few more details?

  • Not. The same application should read the contents of itself, showing what’s on the screen the same way.

  • So if it is in the same application would fall in the case I commented to save the strings, that is, if during the execution it runs several Console.Writeline, just add in a buffer in some class and when you need the console information access this buffer. What is the purpose of accessing the generated log in the console? Scan it for a specific message?

  • I wanted to save everything on my console to a text file...

1 answer

1

Take this example from here:

using System;
using System.IO;

namespace nsStreams
{
  public class Redirect
  {
    static public void Main ()
    {
        FileStream ostrm;
        StreamWriter writer;
        TextWriter oldOut = Console.Out;
        try
        {
            ostrm = new FileStream ("./Redirect.txt", FileMode.OpenOrCreate, FileAccess.Write);
            writer = new StreamWriter (ostrm);
        }
        catch (Exception e)
        {
            Console.WriteLine ("Cannot open Redirect.txt for writing");
            Console.WriteLine (e.Message);
            return;
        }
        Console.SetOut (writer);
        Console.WriteLine ("This is a line of text");
        Console.WriteLine ("Everything written to Console.Write() or");
        Console.WriteLine ("Console.WriteLine() will be written to a file");
        Console.SetOut (oldOut);
        writer.Close();
        ostrm.Close();
        Console.WriteLine ("Done");
      }
   }
}

Details about the Setout here

Source: http://bit.ly/1WxW5JG

  • But there is redirecting the chunk to the file, I want to go to the file/string and also to the Console, simultaneously.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.