在ErrorDataReceived中获取我的流程输出而不是OutputDataReceived

时间:2012-10-12 08:02:14

标签: c# wireshark

在我的应用程序中,我正在打开Tshark进程并开始捕获。为了更新我的UI,我想获得我的进程输出但是我在ErrorDataReceived而不是OutputDataReceived中收到了这个输出。

public void startCapturing()
{
    ProcessStartInfo tsharkStartInfo = new ProcessStartInfo();
    tsharkStartInfo.FileName = _tshark; 
    tsharkStartInfo.RedirectStandardOutput = true; 
    tsharkStartInfo.RedirectStandardError = true; 
    tsharkStartInfo.RedirectStandardInput = true; 
    tsharkStartInfo.UseShellExecute = false; 
    tsharkStartInfo.CreateNoWindow = true; 
    tsharkStartInfo.Arguments = string.Format(" -i " + _interfaceNumber + 
                         " -s " + _packetLimitSize + " -w " + _pcapPath);
    _tsharkProcess.StartInfo = tsharkStartInfo;
    _tsharkProcess.ErrorDataReceived += _cmdProcess_ErrorDataReceived;
    _tsharkProcess.OutputDataReceived += tshark_OutputDataReceived; 
    _tsharkProcess.EnableRaisingEvents = true; 
    _tsharkProcess.Start();
    _tsharkProcess.BeginOutputReadLine(); 
    _tsharkProcess.BeginErrorReadLine();                  
    _tsharkProcess.WaitForExit(); 
}

void _cmdProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
    int.TryParse(e.Data, out _numberOfPackets);                  
}

void tshark_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    string str = e.Data;
}

0 个答案:

没有答案