Question

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?

Was it helpful?

Solution

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);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top