Writing binary data to stdout in c #?

I am trying to write a fast cgi application in C #. I need to go to the stdout stream and write some binary data. The only thing I can find is Console.Write, which accepts text. I also tried

Process.GetCurrentProcess().StandardOutput.BaseStream.Write 

which doesn't work either. Is it possible?

+4
source share
2 answers

Wow, this is a bummer, they did not answer this question after 5 years. Viewed 1800 times.

OpenStandardOutput () exists since .Net 4.0

 using (Stream myOutStream = Console.OpenStandardOutput()) { myOutStream.Write(buf, 0, buf.Length); } 
+9
source

Something like the following (a very quick example is written in notepad):

 using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; [Serializable] public class MyObject { public int n1 = 0; public int n2 = 0; public String str = null; } public class Example { public static void Main() { MyObject obj = new MyObject(); obj.n1 = 1; obj.n2 = 24; obj.str = "Some String"; BinaryFormatter formatter = new BinaryFormatter(); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); sw.AutoFlush = true; Console.SetOut(sw); formatter.Serialize(sw.BaseStream, obj); } } 
+2
source

All Articles