Przechwytywanie wyjścia procesu za pomocą zdarzenia OutputDataReceived
Próbuję przechwycić dane wyjściowe procesu w czasie rzeczywistym (gdy jest uruchomiony). Kod, którego używam, jest raczej prosty (patrz poniżej). Z jakiegoś dziwnego powodu zdarzenie OutputDataReceived nigdy nie jest wywoływane. Czemu?
private void button2_Click(object sender, EventArgs e)
{
// Setup the process start info
var processStartInfo = new ProcessStartInfo("ping.exe", "-t -n 3 192.168.100.1")
{
UseShellExecute = false,
RedirectStandardOutput = true
};
// Setup the process
mProcess = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
// Register event
mProcess.OutputDataReceived += OnOutputDataReceived;
// Start process
mProcess.Start();
mProcess.WaitForExit();
}
void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
//Never gets called...
}