I am wondering if I can pass a command such as "ipconfig /all" in C# to the windows, and get the result back in some variable/array? If so, how?
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
EricPosted Jul 31, 2007, 11:15 AM
Thank you very much again, Mike, you saved my world.
Mike GoldPosted Jul 30, 2007, 3:34 PM
If you want to run the code above using Linux, you'll probably need to use the MONO library for .NET. Microsoft doesn't currently support Linux and Unix, but there is an open source library (mono) that works with Linux.
EricPosted Jul 30, 2007, 2:40 PM
Thanks alot for the help! :)
I hope it can work under linux/unix too, can it?
Mike GoldPosted Jul 30, 2007, 11:41 AM
You can redirect all your standard output into a string. Then you can parse the ipconfig info out of the string into an array:
Process process = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.RedirectStandardOutput = true;
info.FileName = "ipconfig.exe";
info.Arguments = "/all";
info.UseShellExecute = false;
process.StartInfo = info;
process.Start(); string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
// do parsing of output string here