C#调用cmd.exe窗体不显示内容的问题。
命令显示在了标题栏上,应该显示在窗体内才对呀。这是怎么回事??输出文字也不行。

解决方案 »

  1.   

     public static string ExcuteCMD(string[] cmd,bool nowindow)
            {
                if (cmd == null || cmd.Length <= 0) return string.Empty;
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = nowindow;
                p.Start();
                p.StandardInput.AutoFlush = true;
                for (int i = 0; i < cmd.Length; i++)
                {
                    p.StandardInput.WriteLine(cmd[i]);
                }            p.StandardInput.WriteLine("exit");
                string strRst = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                p.Close();
                return strRst;
            }