473,652 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems reading StandardOutput as binary

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.Standar dOutput 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.ReadB ytes(buffer.Len gth)) != 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.
Nov 15 '05 #1
2 3369
dansan <is*********@ho tmail.com> wrote:
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.Standar dOutput 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...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Thanks.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
412
by: John Lewin | last post by:
I've recently discovered the value of using existing console applications in managed .net apps. Unfortunately, I've stumbled into a problem with a particular console application that check's crc info on CDs. Using either the StandardError or StandardOutput streams read, readline or peek methods causes an immediate block that doesn't release until the console app finishes it's business. I want to launch this console app and update my UI to...
0
1184
by: CMG | last post by:
I am trying to run gocr from my program, and use the output. I have done this with success befor, with a workaround command line tool.: Private irfanview As String = "C:\program files\IrfanView\i_view32.exe" Private startuppath As String = Environment.CurrentDirectory & "\" Private pngimage As String = startuppath & "verify.png" Private png2pnm As String = startuppath & "png2pnm.exe" Private gocr As String = startuppath & "gocr.exe"...
2
1612
by: palaga | last post by:
Hi I'm starting an external process that writes data to stdout, and I want to get back these data. So I use myProcess.StandardOutput (everything is correctly set, I can read the data). to read data, I use myProcess.StandardOutput.ReadLine( ). (the data is text). The doc says that if there is no more data available, the function ReadLine return null.
1
1474
by: Yash | last post by:
Hi, Through my VB .NET code , I am trying to invoke a perl script. My aim is to write lines to the script and read from it. With ProcInfo .Arguments = Enricher.EnrichScript + " " + enArgs .RedirectStandardInput = True .RedirectStandardOutput = True .RedirectStandardError = True .UseShellExecute = False .CreateNoWindow = True
0
1285
by: CMG | last post by:
I am trying to run gocr from my program, and use the output. I have done this with success befor, with a workaround command line tool.: Private irfanview As String = "C:\program files\IrfanView\i_view32.exe" Private startuppath As String = Environment.CurrentDirectory & "\" Private pngimage As String = startuppath & "verify.png" Private png2pnm As String = startuppath & "png2pnm.exe" Private gocr As String = startuppath & "gocr.exe"...
4
15066
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that this program returns. I'm just missing the stepshere. I know that I can set the Shell command to an integer,but this only returns a 0 to me telling me that it executed, notwhat is being returned to the console by that application. Isthere a way to...
2
3269
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
8
1524
by: psy_berpunk | last post by:
hey, i'm trying to write a simple program to read gif87a non- interlaced format with a single image-descriptor --- I am using djgpp on windows xp. Sounds simple enough, unfortunatly data in the format is arranged primarily in single-byte unsigned integers. So i've been reading them in a chars and casting them as unsigned chars into an int.
2
5837
by: steve005 | last post by:
Hi, I am writing a binary file with matlab that consists of a couple hundred double values and then reading it in with c++. The problem arises in c++ when I try and read in the files. At a specific point it stops and wont read any more values. I use this code to open it and read it: if( (err = fopen_s( &fp,"C:/simfile1.tmg0" , "rb" )) != 0 ); fread(&coneAngle,sizeof(double),1,fp); After about twenty simmilar reads it fails, returns an...
0
8370
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.