public interface IRunConsole
{
void Run();
}
public abstract class RunConsole:IRunConsole
{
public abstract string[] Args { get; }
public abstract string FileName { get; }//CMD
public string result;
public string error;
public virtual int WaitExitedTime {
get {
return ;
}
}
#region IRunConsole 成员 public void Run()
{
using(System.Diagnostics.Process process = new System.Diagnostics.Process()){
process.StartInfo = new System.Diagnostics.ProcessStartInfo(FileName)
{
RedirectStandardOutput=true,
RedirectStandardInput=true,
CreateNoWindow=true,
UseShellExecute=false,
RedirectStandardError = true
};
process.Start();
foreach (string arg in Args) {
process.StandardInput.WriteLine(arg);
} process.StandardInput.WriteLine(@"exit");
process.WaitForExit();
this.result = process.StandardOutput.ReadToEnd();
this.error = process.StandardError.ReadToEnd();
process.Close();
if (!string.IsNullOrEmpty(this.error)) {
throw new Exception(this.error);
}
}
} #endregion
}
 public class RunDelDirectory : RunConsole
{
public string DirPath
{
get;
set;
}
public override string[] Args
{
get {
return new string[]{
string.Format("rd /s/q {0}",this.DirPath)
};
}
} public override string FileName
{
get { return "cmd"; }
}
}

【C#】调用DOS命令的更多相关文章

  1. C#如何调用DOS命令

    在使用C#编辑过程中,通常需要利用外部命令来执行一些操作,从而完成特定的功能.下面小编就以利用C#调用DOS命令"Ver"显示系统版本号为例,给初学C#语言的网友讲解一下具体的调用 ...

  2. ASP.NET调用dos命令获取交换机流量

    protected void btn_Cisco_Click(object sender, EventArgs e) { try { string ip = txt_ip.Value; string ...

  3. matlab 调用dos命令和文件操作

    第一.利用!直接调用,简单方便,可以带操作对象:!del A.bat 第二.调用system函数或者dos函数,既可以实现功能,又返回参数,能检查执行情况,方便后面程序的开发,推荐这个 [status ...

  4. 如何在C语言 C++里面调用 DOS命令

    C里面调用可以用[system("命令")]这样的形式. 但需要include <stdlib.h> 例子如下: #include <stdio.h> #i ...

  5. c++调用DOS命令,不显示黑屏

    WinExec("Cmd.exe /C md c://12", SW_HIDE); 注释:/c是什么意思,不用/C会报错 CMD [/A | /U] [/Q] [/D] [/E:O ...

  6. c++ CreateProcess调用dos命令

    // test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <windows.h> #include &l ...

  7. C# 调用DOS 命令

    class NetWorkDeviceInfo { public static string GetDeviceInfo() { System.Diagnostics.Process p = new  ...

  8. java程序中调用Linux命令Windows命令

    目前总结的方法: 调用Linux简单的命令行,设置文件夹权限755 String scriptDir = "/home/wenf"; String cmd = "chmo ...

  9. DOS命令教学之详解批处理

    批处理文件是由一个或一个以上的DOS命令及可执行命令组成的带有扩展名.BAT的文件.当用户以批处理文件名为命令时,DOS会自动依次执行文件中的命令.批处理文件的特点是一次建立可多次执行.下面,寻修网h ...

随机推荐

  1. IOS新手教程(二)-控制流

    int main(){ //2.控制流 //2.1 if语句 //1. if(expression){ } //2. if(expression){ }else{ } //3.能够有0个或是多个els ...

  2. hdu 1002 Java 大数 加法

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 PE   由于最后一个CASE不须要输出空行 import java.math.BigInteger; i ...

  3. C# mongodb 1

    转载C# mongodb 概述 MongoDB是一个高性能,开源,无模式的文档型数据库,使用C++开发.是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他 ...

  4. Socket 学习(三)

    前2节,说的是 Server 与 Client 的数据交互.服务端IP.端口固定,客户端 网服务端发送消息的时候,他的Socket对面被服务端获取到了,而且链接没有中断,他当然可以很容易回复信息. 现 ...

  5. MySQL引擎的相关知识

    MySQL数 据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引 擎:ISAM.MYISAM和HEAP.另外两种类型I ...

  6. linux 安装httpd(验证通过)

    一.安装apache(http服务) 1. 从apache.org下载源码安装包 2. 解压缩 # tar zxf httpd-2.2.4.tar.gz # cd httpd-2.2.4 3. 安装a ...

  7. hibernate之使用Annotation注解搭建项目

    之前开发都是使用xml配置来开发项目,开发起来特别繁琐 大家会发现通过注解大大简化了我们开发流程,使我们从繁琐的XML配置中解放出来. 第一步:新建一个javaweb项目.并将hibernate需要的 ...

  8. s2sh三大框架整合过程(仅供参考)

    三大框架顾名思义就是非常有名的Struts2 ,Hibernate,Spring, 框架整合的方法很多,现在我写一个非常简单的整合过程,相信大家一看就会! 这里使用的struts-2.2.1.1.hi ...

  9. AngulaJS实战

    AngulaJS实战总结, 带你进入AngularJS世界(待续)   使用AngularJS  进行Hybrid App 开发已经有一年多时间了,这里做一个总结. 一.AngularJS 初始化加载 ...

  10. 使用SoapUI 测试Web Service

    原文:使用SoapUI 测试Web Service 如何测试写好的Webservice?你当然可以写代码来测试,但还是太麻烦,你得花时间去学习各语言的关于Webservice调用的相关API.这里推荐 ...