C# 执行CMD 命令

        /// <summary>
        /// 执行CMD 命令
        /// </summary>
        /// <param name="strCommand">命令串</param>
        /// <returns></returns>
        public static string RunCommand(string strCommand)
        {
            Process process = new Process();
            process.StartInfo.FileName = "CMD.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
            process.Start();
            process.StandardInput.WriteLine(strCommand);
            process.StandardInput.WriteLine("exit");
            string str = process.StandardOutput.ReadToEnd();
            process.Close();
            return str;
        }

 

posted @ 2015-11-23 15:09  bobo-bobo  阅读(160)  评论(0编辑  收藏  举报