Friday, May 4, 2012

Call a command line function from C#



            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.FileName = "cmd";
            p.StartInfo.Arguments = "/C ipconfig /all";
            p.Start();
            StreamReader sr = p.StandardOutput;
        
            while ((sr.ReadLine()) != null)
            {
                Console.WriteLine(sr.ReadLine());
            }



No comments: