プロセス出力を「リアルタイム」でキャプチャしようとしています(実行中)。私が使用するコードはかなり単純です(以下を参照)。奇妙な理由で、OutputDataReceivedイベントが呼び出されることはありません。なんで?
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...
}