【C#】调用DOS命令
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命令的更多相关文章
- C#如何调用DOS命令
在使用C#编辑过程中,通常需要利用外部命令来执行一些操作,从而完成特定的功能.下面小编就以利用C#调用DOS命令"Ver"显示系统版本号为例,给初学C#语言的网友讲解一下具体的调用 ...
- ASP.NET调用dos命令获取交换机流量
protected void btn_Cisco_Click(object sender, EventArgs e) { try { string ip = txt_ip.Value; string ...
- matlab 调用dos命令和文件操作
第一.利用!直接调用,简单方便,可以带操作对象:!del A.bat 第二.调用system函数或者dos函数,既可以实现功能,又返回参数,能检查执行情况,方便后面程序的开发,推荐这个 [status ...
- 如何在C语言 C++里面调用 DOS命令
C里面调用可以用[system("命令")]这样的形式. 但需要include <stdlib.h> 例子如下: #include <stdio.h> #i ...
- c++调用DOS命令,不显示黑屏
WinExec("Cmd.exe /C md c://12", SW_HIDE); 注释:/c是什么意思,不用/C会报错 CMD [/A | /U] [/Q] [/D] [/E:O ...
- c++ CreateProcess调用dos命令
// test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <windows.h> #include &l ...
- C# 调用DOS 命令
class NetWorkDeviceInfo { public static string GetDeviceInfo() { System.Diagnostics.Process p = new ...
- java程序中调用Linux命令Windows命令
目前总结的方法: 调用Linux简单的命令行,设置文件夹权限755 String scriptDir = "/home/wenf"; String cmd = "chmo ...
- DOS命令教学之详解批处理
批处理文件是由一个或一个以上的DOS命令及可执行命令组成的带有扩展名.BAT的文件.当用户以批处理文件名为命令时,DOS会自动依次执行文件中的命令.批处理文件的特点是一次建立可多次执行.下面,寻修网h ...
随机推荐
- 前端学习笔记(zepto或jquery)——对li标签的相关操作(四)
对li标签的相关操作——五种方式给奇数项li标签设置样式 demo演示: 1 2 3 4 5 6 7 // 详解: 通常我们为多个li添加样式时常用的是使用filter,但我们在第三节中可以看到fil ...
- SDUT 1124-飞跃荒野(三维BFS)
飞跃原野 Time Limit: 5000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 勇敢的法里奥出色的完毕了任务之后.正在迅速地向自己的基地撤退.但因为 ...
- jQuery性能优化38建议---最引人注目的用户体验!
一.需要注意的是的定义jQuery当变量被添加varkeyword 然而,这并不jQuery.整个javascript开发过程,所有需要注意,一定不要将其定义为下面的示例: $loading = $( ...
- OpenVPN多实例优化的思考过程
1.sss 当构建组件之间的关系已经错综复杂到接近于一张全然图的时候,就要换一个思路了,或者你须要重构整个系统,或者你将又一次实现一个. 2.TAP网卡和TUN网卡 2.1.TAP的优势 1.方便组网 ...
- 使用C语言编写windows服务一般框架
原文:使用C语言编写windows服务一般框架 编写windows服务和编写windows应用程序一样,有一些回调函数必须填写且向windows 服务管理器(service manager)进行注册, ...
- C# .NET ASP.NET 其中关系你了解多少
有些人一直在做这方面..但突然有人来问你这些问题..估计有很多答不上来. 1..NET是一个平台,一个抽象的平台的概念. .NET平台其本身实现的方式其实还是库,抽象层面上来看是一个平台. 个人理解. ...
- mvc之验证IEnumerable<T> 类型,多选框验证
原文:mvc之验证IEnumerable<T> 类型,多选框验证 假设我们有这么一种需求,我们要同时添加年级和年级下面的多个班级,我们一般会像下面这种做法. Action中我们这样接收: ...
- Arraylist、Linkedlist遍历方式性能分析
本文主要介绍ArrayList和LinkedList这两种list的常用循环遍历方式,各种方式的性能分析.熟悉java的知道,常用的list的遍历方式有以下几种: 1.for-each List< ...
- C#6.0 中的那些新特性
C#6.0 中的那些新特性 前言 VS2015在自己机器上确实是装好了,费了老劲了,想来体验一下跨平台的快感,结果被微软狠狠的来了一棒子了,装好了还是没什么用,应该还需要装Xarmain插件,配置一些 ...
- ylb:SQLServer常用系统函数-字符串函数、配置函数、系统统计函数
原文:ylb:SQLServer常用系统函数-字符串函数.配置函数.系统统计函数 ylbtech-SQL Server:SQL Server-SQLServer常用系统函数 -- ========== ...