KovBal
KovBal

Reputation: 2177

How to stream binary data to standard output in .NET?

I'm trying to stream binary data to the standard output in .NET. However you can only write char using the Console class. I want to use it with redirection. Is there a way to do this?

Upvotes: 4

Views: 2601

Answers (1)

Frank Krueger
Frank Krueger

Reputation: 71013

You can access the output stream using Console.OpenStandardOutput.

    static void Main(string[] args) {
        MemoryStream data = new MemoryStream(Encoding.UTF8.GetBytes("Some data"));
        using (Stream console = Console.OpenStandardOutput()) {
            data.CopyTo(console);
        }
    }

Upvotes: 6

Related Questions