I have a C# application that needs to show certain data via SNMP. I am using the Net-SNMP on Windows and running the command
snmpwalk -Os -c <community_string> -v 2c <hostname> system
To get all variables under system.
On the command prompt it shows a line-by-line output for each variable retrieved. But when I run it via C# it shows all output at once using the following code. How can I get the output dynamically i.e. line by line as in command prompt.
Process proc = new Process();
proc.StartInfo.FileName = "snmpwalk.exe";
proc.StartInfo.Arguments = "-Os -C <community_string> -v 2c <hostname> system";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.OutputDataReceived += (sender, e) => Console.WriteLine("{0}", e.Data);
proc.Start();
proc.BeginOutputReadLine();
The same code when replaced for a command like ping
shows a dynamic line-by-line output.