What would be a good way to collect data from the command prompt in a C# Winforms Application?

It's pretty much perfect for requesting data back from foreign boxes.

It's pretty much perfect for requesting data back from foreign boxes. Suggested reading: blogs.msdn.com/b/spike/archive/2010/02/0... Alternatively, google for: powershell netstat In terms of C#, you probably want GetActiveTcpConnections(): msdn.microsoft.com/en-us/library/system....).aspx.

To be honest with you, PowerShell was never something I dipped my toes into, but now that you mention it, I think I should if it would be a helpful tool. Thanks for the idea! – Jared Apr 15 at 3:37.

Scraping the output of a command prompt is one approach - here's a stackoverflow post about copy & pasting from a console window a more substantial approach would be build your own netstat implementation like this guy did.

I really like having my applications to be self-substantial and not have the need to rely on many outside sources, so the idea of building my own netstat implementation sounds like a great one. However, I can't really read the code right now because I'm away from my computer currently and the code is getting cut off of my iPhone's browser screen for some dumb reason. I'm planning on trying out your idea tomorrow and seeing if it works.

Thanks! – Jared Apr 15 at 3:43.

Use a Process to run the command and capture its output: How to spawn a process and capture its STDOUT in . NET?

Yeah, much less hacky than my suggestion of redirecting to a text file :) – Matt Apr 15 at 2:24.

A bit of a hack, but you could redirect the output of netstat to a file "netstat -noa > c:\netstat. Txt" and then load the file and parse it...

Then a future version of Windows will change the format of netstat's output and it'll break your program. Instead of doing a "screenscraping" hack why don't you just call actual Windows APIs that will provide you the data that you are looking for? This is what Windows Managmenent Instrumentation is for.

How can I access netstat-like Ethernet statistics from a Windows program.

You can use System.Diagnostics. Process and set the RedirectStandardOutput property of startinfo to true. This way you will be able to get the StandardOutput as streamreader.

Make sure to set the UseShellExecute property to false and the CreateNoWindow property to true.

If yes please share it may help someone. – Subhash Lama Apr 21 at 1:13.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions