2
獲取二進制數據,我開始用代碼與下圖類似的過程:從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)
{
}
我遇到的問題是,對象有一個Data
屬性,它是一個字符串。我需要將標準輸出數據作爲二進制數據讀取。我猜測沒有辦法將字符串數據恢復到適當的二進制數據中,所以使用不同方法接收二進制數據的任何建議都會很棒。
請參閱「從Process.StandardOutput捕獲二進制輸出」(http://stackoverflow.com/questions/4143281/capturing-binary-output-from-process-standardoutput),儘管使用拉方法,而不是推(與正如你試圖做的那樣,OutputDataReceived事件處理程序)。 –