码迷,mamicode.com
首页 > Windows程序 > 详细

C#执行cmd命令

时间:2017-09-20 19:36:50      阅读:552      评论:0      收藏:0      [点我收藏+]

标签:redirect   ror   use   turn   options   creat   tao   信息   write   

Process p = new Process();//创建进程对象
p.StartInfo.FileName = "cmd.exe";//设定需要执行的命令
// startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出
p.StartInfo.UseShellExecute = false;//不使用系统外壳程序启动
p.StartInfo.RedirectStandardInput = true;//可以重定向输入 11
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;//不创建窗口
p.Start();

StringBuilder sb = new StringBuilder();
sb.Append(“......”);

p.StandardInput.WriteLine(sb.ToString());

补充:

验证IP地址:

private bool IsIPAddress(string strip)
{
  if (strip.Length < 7 || strip.Length > 15)
  return false;

  if (strip.StartsWith("127") == true)
  {
    return false;
  }
  string regformat = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$";
  Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
  return regex.IsMatch(strip);
}

复制信息到剪贴板:

Clipboard.SetDataObject(“”);此处是调用的Clipboard的API接口

 

C#执行cmd命令

标签:redirect   ror   use   turn   options   creat   tao   信息   write   

原文地址:http://www.cnblogs.com/candyzhmm/p/7562840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!