Tag: 重定向标准输出

从StandardOutput获取二进制数据

我正在开始一个代码类似于下面的代码: // 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属性是一个字符串。 我需要读取标准输出数据作为二进制数据。 我猜测没有办法将字符串数据恢复到适当的二进制数据中,因此任何使用不同方法接收二进制数据的建议都会很棒。