Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Binary Data from StandardOutput

I'm starting a process with code similar to that below:

// some of the flags are not needed
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.EnableRaisingEvents = true;
process.OutputDataReceived += process_OutputDataReceived;
process.ErrorDataReceived += process_OutputDataReceived;
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();

void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
}

void process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
}

The issue I'm running into is that the DataReceivedEventArgs object has a Data property which is a string. I need to read the standard output data as the binary data it is. I'm guessing there's no way to get the string data back into it's appropriate binary data, so any suggestions on using a different method for receiving the binary data would be great.

like image 790
Brian Hasden Avatar asked Oct 30 '25 06:10

Brian Hasden


1 Answers

Bradley Grainger who made a comment on the question was right. The event handlers don't support retrieving binary data from standard out. Had to switch over to using a main loop and pulling data from standard out using the read functions.

like image 88
Brian Hasden Avatar answered Oct 31 '25 22:10

Brian Hasden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!