tags:

views:

396

answers:

2

Related to this question http://stackoverflow.com/questions/1284088/encrypt-binary-with-7z-without-filenames/1284101#1284101

In C# how can i put binary in STDin? i was hoping the below would work but it doesnt. And it makes sense. So how do i push a byte[] array?

new BinaryWriter(p.StandardInput.FormatProvider);
A: 

stdin is just another byte stream, one your program can read from

Stream st=Console.OpenStandardInput ();
StreamReader sr=new StreamReader(st);

etc. In the q. which you refer to, the material coming in from stdin is being piped from the output of another program. To do that part of the process, you use Console.OpenStandardOuput() to get a stream and push the binary out through that.

Steve Gilham
Yes, but if you're dealing with binary, you don't want to use `StreamReader`, which is derived from `TextReader`.
John Saunders
Yes -- should be BinaryReader.
Steve Gilham
Well, maybe or maybe not. If you just want to deal with bytes, then dealing with the raw stream is fine. Other things like the `BinaryFormatter` will also be useful - just not a `TextReader`.
John Saunders
+1  A: 

Write directly to the base stream:


new BinaryWriter(p.StandardInput.BaseStream)
Alfred Myers
Or use `p.StandardInput.BaseStream.Write`.
John Saunders