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 好听的元旦简短祝福语