Getting Binary Data from StandardOutput

给你一囗甜甜゛ 提交于 2019-12-02 05:43:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6803675/getting-binary-data-from-standardoutput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!