码迷,mamicode.com
首页 > Windows程序 > 详细

C# 执行CMD 命令

时间:2015-11-23 16:46:58      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

        /// <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;
        }

 

C# 执行CMD 命令

标签:

原文地址:http://www.cnblogs.com/ilookbo/p/4988530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!