当前位置:编程学习 > C#/ASP.NET >>

.NET 程序,调用其它程序

.NET 程序,调用其它程序
using System;
using System.Diagnostics;
namespace Jmv_Demo
{
/// <summary>
/// CmdUtility 的摘要说明。
/// </summary>
public class CmdUtility
{

/// <summary>
/// 执行cmd.exe命令
/// </summary>
/// <param name="commandText">命令文本</param>
/// <returns>命令输出文本</returns>
public string ExeCommand(string commandText)
{
return ExeCommand(new string []{commandText});
}
/// <summary>
/// 执行多条cmd.exe命令
/// </summary>
/// <param name="commandArray">命令文本数组</param>
/// <returns>命令输出文本</returns>
public string ExeCommand(string [] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach(string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
strOutput = e.Message;
补充:asp.net教程,基础入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,