資源簡介
.net調用系統cmd指令類,內含直接調用cmd指令得到返回內容的方法
代碼片段和文件信息
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;
????????///?
????????///?構造方法
????????///?
????????public?Cmd()
????????{
????????????proc?=?new?Process();
????????}
????????///?
????????///?執行CMD語句
????????///?
????????///?要執行的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();
?????
- 上一篇:基于C#的FTP上傳Demo
- 下一篇:C#網絡編程UDP廣播
評論
共有 條評論