資源簡介
.net調(diào)用系統(tǒng)cmd指令類,內(nèi)含直接調(diào)用cmd指令得到返回內(nèi)容的方法
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Diagnostics;
namespace?BRS
{
????///?
????///?Cmd?的摘要說明。
????///?
????public?class?Cmd
????{
????????private?Process?proc?=?null;
????????///?
????????///?構(gòu)造方法
????????///?
????????public?Cmd()
????????{
????????????proc?=?new?Process();
????????}
????????///?
????????///?執(zhí)行CMD語句
????????///?
????????///?要執(zhí)行的CMD命令
????????public?string?RunCmd(string?cmd)
????????{
????????????proc.StartInfo.CreateNoWindow?=?true;
????????????proc.StartInfo.FileName?=?“cmd.exe“;
????????????proc.StartInfo.UseShellExecute?=?false;
????????????proc.StartInfo.RedirectStandardError?=?true;
????????????proc.StartInfo.RedirectStandardInput?=?true;
????????????proc.StartInfo.RedirectStandardOutput?=?true;
????????????proc.Start();
????????????proc.StandardInput.WriteLine(cmd);
????????????proc.StandardInput.WriteLine(“exit“);
????????????string?outStr?=?proc.StandardOutput.ReadToEnd();
?????
評論
共有 條評論