.Net程序操作CMD命令

 使用代码操作CMD命令行程序
public void ExecuteCmd(string cmd)
{
            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 = true;
            p.Start();
            //设置自动刷新缓冲并更新
            p.StandardInput.AutoFlush = true;
            //写入命令
            p.StandardInput.WriteLine(cmd);
            p.StandardInput.WriteLine("exit");
            //等待结束
            p.WaitForExit();
            p.Close();
 }


OK!有了这个就可以执行一些C#不能操作的内容啦.................
posted @ 2011-04-12 21:11  JasNature  阅读(1285)  评论(5编辑  收藏  举报
我要赞个
我要评论
我要收藏