从StandardOutput获取二进制数据 [英] Getting Binary Data from StandardOutput

查看:157
本文介绍了从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)
{
}

我遇到的问题是DataReceivedEventArgs对象具有Data属性,该属性是字符串.我需要将标准输出数据读取为二进制数据.我猜想没有办法将字符串数据恢复为合适的二进制数据,因此,关于使用其他方法接收二进制数据的任何建议都是很好的.

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.

推荐答案

对这个问题发表评论的布拉德利·格兰杰(Bradley Grainger)是正确的.事件处理程序不支持从标准输出中检索二进制数据.必须切换到使用主循环,并使用读取功能从标准中提取数据.

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.

这篇关于从StandardOutput获取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆