Problems reading StandardOutput as binary

D

dansan

I have been tryning to make some of our C# programs talk to some perl
programs. These perl jewels output in binary. I have been trying to
use Process.StandardOutput to read the output from the perl programs.

I am able to read the output if it is ASCII (or some char[] of some
sort). But the issues comes when it is binary info. I have tried to
use StandardOutput.BaseStream, which returns a Stream to then read the
bytes out of that Stream. This stream does not support 'searching',
therefore I can't do .Length on it... and I can't loop-until-done
because I don't know how to stop when I'm at the end of the stream.

I have tried all kinds of lines, one of which is:

byte [] buffer = new byte [size];
while ((buffer = binreader.ReadBytes(buffer.Length)) != null)
{
.... write the buffer to a binary file...
}

but that doesn't work.

I have also tried to read one byte at a time, but with no success
either.


How can I do this? Where can I read more about it?

Thanks for helping :)

Daniel.
 
J

Jon Skeet

dansan said:
I have been tryning to make some of our C# programs talk to some perl
programs. These perl jewels output in binary. I have been trying to
use Process.StandardOutput to read the output from the perl programs.

I am able to read the output if it is ASCII (or some char[] of some
sort). But the issues comes when it is binary info. I have tried to
use StandardOutput.BaseStream, which returns a Stream to then read the
bytes out of that Stream. This stream does not support 'searching',
therefore I can't do .Length on it... and I can't loop-until-done
because I don't know how to stop when I'm at the end of the stream.

You stop at the end of the stream by noting when Read returns -1. See
http://www.pobox.com/~skeet/csharp/readbinary.html

However, I don't know whether some other encoding stuff may get applied
to the stream before you get a chance to look at it. It doesn't "feel"
like a nice thing, I'm afraid...
 

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