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