C#执行Windows的dos命令
来源:互联网 发布:下载itools软件 降级 编辑:程序博客网 时间:2024/05/24 04:56
不管单行还是多行dos命令,你都可以轻松执行。
private void button2_Click(object sender, EventArgs e)
{
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; true表示不显示黑框,false表示显示dos界面
p.Start();
p.StandardInput.WriteLine("d:");
p.StandardInput.WriteLine("md core2");
p.StandardInput.WriteLine("cd core2");
p.StandardInput.WriteLine("md shootman2");
p.Close();
}
到d盘去看一下,是不是多了“core2”文件夹,文件夹里面有个“shootman2”文件夹啊?
呵呵,是的!这就是process调用“cmd.exe”后执行命令的方法。
如果不需要返回结果可以这样
Process.Start("cmd.exe", @"/c net start mssqlserver");
private void button2_Click(object sender, EventArgs e)
{
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; true表示不显示黑框,false表示显示dos界面
p.Start();
p.StandardInput.WriteLine("d:");
p.StandardInput.WriteLine("md core2");
p.StandardInput.WriteLine("cd core2");
p.StandardInput.WriteLine("md shootman2");
p.Close();
}
到d盘去看一下,是不是多了“core2”文件夹,文件夹里面有个“shootman2”文件夹啊?
呵呵,是的!这就是process调用“cmd.exe”后执行命令的方法。
如果不需要返回结果可以这样
Process.Start("cmd.exe", @"/c net start mssqlserver");
- 让c#执行windows的dos命令
- C#执行Windows的dos命令
- C#执行Windows的dos命令
- c#执行Dos命令
- C#执行DOS命令
- c#执行DOS命令
- c#执行Dos命令
- c#执行Dos命令
- C#执行DOS命令
- C#执行DOS命令,返回DOS命令的输出
- C#执行DOS命令,返回DOS命令的输出
- c#代码执行DOS命令
- C#调用执行DOS命令
- C#如何执行DOS命令
- c#中执行dos命令
- C#中执行dos命令
- c# winform执行DOS命令
- c# 调用CMD命令执行dos命令
- 数组逆置算法
- 动态生成编译运行java类
- 所谓微软面试题的解答:求一个字符串中连续出现次数最多的子串
- Makefile学习(转载)
- C#绘制圆角窗体
- C#执行Windows的dos命令
- 在当前事件中调用另一个事件
- 4月竹海行
- 一个多线程程序
- Design Float-设计类的digg网站
- 使用独立的DLL来存储图片(资源文件)
- 往事、回忆、轮回…… 《美国往事》
- C#通过ADO.NET建表
- 2440 module test, hello world - life sucks