EDN Admin
Well-known member
As a trouble shooting tool, I am working on a C# class that will run netstat, capture the output, process it, and enlighten users as to where port conflicts exits. The problem I am running into is that I am only getting the header output. Here
is the complete code, what am I missing?
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; class NetstatMgr
{
<span style="color:Blue; private List<<span style="color:Blue; string> _netstatLines = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; public NetstatMgr()
{
ProcessStartInfo psi = <span style="color:Blue; new ProcessStartInfo(<span style="color:#A31515; "netstat", <span style="color:#A31515; "-nop");
psi.CreateNoWindow = <span style="color:Blue; true;
psi.ErrorDialog = <span style="color:Blue; false;
psi.UseShellExecute = <span style="color:Blue; false;
psi.RedirectStandardOutput = <span style="color:Blue; true;
psi.RedirectStandardError = <span style="color:Blue; true;
psi.Verb = <span style="color:#A31515; "runas";
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process process = <span style="color:Blue; new Process();
process.EnableRaisingEvents = <span style="color:Blue; true;
process.StartInfo = psi;
process.ErrorDataReceived += (s, e) => { _netstatLines.Add(e.Data); };
process.OutputDataReceived += (s, e) => { _netstatLines.Add(e.Data); };
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
<span style="color:Green; // process.Exited += process_Exited;
<span style="color:Green; //}
<span style="color:Green; //void process_Exited(object sender, EventArgs e)
<span style="color:Green; //{
Debug.WriteLine(<span style="color:#A31515; "Done!");
<span style="color:Blue; foreach (<span style="color:Blue; var s <span style="color:Blue; in _netstatLines)
Debug.WriteLine(s);
}
}
[/code]
View the full article
is the complete code, what am I missing?
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; class NetstatMgr
{
<span style="color:Blue; private List<<span style="color:Blue; string> _netstatLines = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; public NetstatMgr()
{
ProcessStartInfo psi = <span style="color:Blue; new ProcessStartInfo(<span style="color:#A31515; "netstat", <span style="color:#A31515; "-nop");
psi.CreateNoWindow = <span style="color:Blue; true;
psi.ErrorDialog = <span style="color:Blue; false;
psi.UseShellExecute = <span style="color:Blue; false;
psi.RedirectStandardOutput = <span style="color:Blue; true;
psi.RedirectStandardError = <span style="color:Blue; true;
psi.Verb = <span style="color:#A31515; "runas";
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process process = <span style="color:Blue; new Process();
process.EnableRaisingEvents = <span style="color:Blue; true;
process.StartInfo = psi;
process.ErrorDataReceived += (s, e) => { _netstatLines.Add(e.Data); };
process.OutputDataReceived += (s, e) => { _netstatLines.Add(e.Data); };
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
<span style="color:Green; // process.Exited += process_Exited;
<span style="color:Green; //}
<span style="color:Green; //void process_Exited(object sender, EventArgs e)
<span style="color:Green; //{
Debug.WriteLine(<span style="color:#A31515; "Done!");
<span style="color:Blue; foreach (<span style="color:Blue; var s <span style="color:Blue; in _netstatLines)
Debug.WriteLine(s);
}
}
[/code]
View the full article