六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 41|回复: 0

C# 调用cmd.exe的方法

[复制链接]

升级  92.5%

932

主题

932

主题

932

主题

探花

Rank: 6Rank: 6

积分
2850
 楼主| 发表于 2013-2-1 09:51:08 | 显示全部楼层 |阅读模式
网上有很多用C#调用cmd的方法,大致如下:

<span style="color: #000000;">private void ExecuteCmd(string command)        {            Process p = new Process();            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.CreateNoWindow = true;            p.Start();            p.StandardInput.WriteLine(command);            p.StandardInput.WriteLine("exit");            p.WaitForExit();            this.textBox1.Text=textBox1.Text+ p.StandardOutput.ReadToEnd();            p.Close();        }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表