Console encoding

D

David Michaels

Is it possible to change the encoding of Console.Out (I think not), or, how
can output just raw bytes to stdout? There is no Console.Write() overload
which takes a byte (the one that takes an object just does a ToString() on a
given byte object). I understand why Console would force it's own encoding
on stdout when simply outputting text to a console (dos box) window, but if
I'm redirecting/piping to another console, I want raw bytes. Any ideas?
Thanks.
 
L

Lau Lei Cheong

The short answer is that DrawString() API only accept string, so even if you
enforce it to accept byte, it'll have to convert it to string
later anyway.

If you really want to push "bytes" to Console.Out, you'll probably want to
try Console.OpenStandardOutput() method which will
open a normal Steam object.
 
M

Mihai N.

Is it possible to change the encoding of Console.Out (I think not), or, how
can output just raw bytes to stdout? There is no Console.Write() overload
which takes a byte (the one that takes an object just does a ToString() on a
given byte object). I understand why Console would force it's own encoding
on stdout when simply outputting text to a console (dos box) window, but if
I'm redirecting/piping to another console, I want raw bytes. Any ideas?
Try Console.OutputEncoding/Console.InputEncoding.
Present in .NET 2.0 only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top