[置顶] c#程序中如何执行 dos命令
2011-10-13 11:07
381 查看
C#中执行Dos命令 C# 本来封装了很多 类似于Dos命令的东西,可是开发需要用它来执行 cmd.texe。
static void Main(string[] args)
{
command.startcmd("ping");
command.cmdPross("ping", "127.0.0.1");
}
public static string cmdPross(string command, string argument)
{
string output = "";
try
{
Process cmd = new Process();
cmd.StartInfo.FileName = command;
cmd.StartInfo.Arguments = argument;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start();
output = cmd.StandardOutput.ReadToEnd();
Console.WriteLine(output);
cmd.WaitForExit();
cmd.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
}
return output;
}
static void Main(string[] args)
{
command.startcmd("ping");
command.cmdPross("ping", "127.0.0.1");
}
public static string cmdPross(string command, string argument)
{
string output = "";
try
{
Process cmd = new Process();
cmd.StartInfo.FileName = command;
cmd.StartInfo.Arguments = argument;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start();
output = cmd.StandardOutput.ReadToEnd();
Console.WriteLine(output);
cmd.WaitForExit();
cmd.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
}
return output;
}
相关文章推荐
- c#程序中如何执行 dos命令
- C#中利用process类调用外部程序以及执行dos命令
- C#如何执行DOS命令
- 如何在ASP.NET程序里面执行DOS命令
- C#中利用process类调用外部程序以及执行dos命令 - ASP.NET
- C# 程序一个cmd命令窗口执行多条dos命令
- 如何用C#程序直接执行.sql文件里的SQL语句
- 【转】C#执行命令行程序/命令并获取输出结果
- c# 程序调用cmd执行命令如SVN.exe
- Services开源框架之CXF与在java程序中如何实现操作cmd执行网络命令
- C# WINForm 如何关闭系统进程,调用cmd并执行命令(隐藏CMD窗口) - 赤色火焰 - 京华志
- 用C#调用CMD.exe,执行DOS命令
- 如何执行一条命令在C#里面。Process
- 转载:C程序中如何获取命令执行的结果
- 使用C#调用外部序或是执行DOS命令
- C# 如何调用可执行程序传参
- C#执行Windows的dos命令
- C程序中如何获取shell命令执行结果和返回值
- 使用C#调用外部序或是执行DOS命令
- 做练习时写了一个调用DOS命令删文件夹及子目录和文件的C#程序