我正在用类似于下面的代码开始一个过程:
// 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
属性,它是一个字符串。我需要将标准输出数据读取为二进制数据。我猜想没有办法将字符串数据恢复为适当的二进制数据,因此任何关于使用不同方法接收二进制数据的建议都会很棒。
最佳答案
Bradley Grainger 对这个问题发表了评论是对的。事件处理程序不支持从标准输出中检索二进制数据。不得不切换到使用主循环并使用读取函数从标准输出中提取数据。
关于c# - 从 StandardOutput 获取二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6803675/