3

在我的应用程序中,我打开一个 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;
}
4

0 回答 0