C#挪用CMD敕令實例。本站提示廣大學習愛好者:(C#挪用CMD敕令實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C#挪用CMD敕令實例正文
有時刻有一些DOS敕令須要我們在履行法式的時刻挪用,這須要應用C#供給的相干接口。
代碼以下,很簡略,信任年夜家都能看懂,我就不贅述了。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;//這個是停止dos敕令挪用
namespace ExecuteCMD
{
//完成讀取Excel文件的功效
class ExecuteCMD
{
public static void CreateDll(){
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 = false;
p.Start();
p.StandardInput.WriteLine("systeminfo");
Console.Write(p.StandardOutput.ReadToEnd());
p.StandardInput.WriteLine("exit");
}
}
}