C# interact with Command prompt

using System.IO;
using System.Diagnostics;
static void Main(string[] args)
        {
            CmdDemo("dir");
            Console.ReadLine();
        }

        static void CmdDemo(string cmdText)
        {
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "cmd.exe",
                    Arguments = string.Format("/c {0}",cmdText),
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    RedirectStandardOutput = true
                }
            };
            proc.Start();
            proc.WaitForExit();
            Console.WriteLine(proc.StandardOutput.ReadToEnd());
        }
(0)

相关推荐