C#调用CMD命令实例
有时候有一些DOS命令需要我们在执行程序的时候调用,这需要使用C#提供的相关接口。
代码如下,很简单,相信大家都能看懂,我就不赘述了。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Diagnostics;//这个是进行dos命令调用
namespaceExecuteCMD
{
//实现读取Excel文件的功能
classExecuteCMD
{
publicstaticvoidCreateDll(){
Processp=newProcess();
p.StartInfo.FileName="cmd.exe";
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardInput=true;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.RedirectStandardError=true;
p.StartInfo.CreateNoWindow=false;
p.Start();
p.StandardInput.WriteLine("systeminfo");
Console.Write(p.StandardOutput.ReadToEnd());
p.StandardInput.WriteLine("exit");
}
}
}热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短