日期:2014-05-17 浏览次数:20536 次
protected void Page_Load(object sender, EventArgs e)
{
comm cm = new comm();
//Response.Write(cm.RumCmd("ping www.baidu.com"));//可成功
cm.RunProgram("C:\\Program Files\\SWFTools\\pdf2swf.exe", "test.pdf test1.swf");
}
public class comm
{
private Process p = null;
public comm()
{
p = new Process();
}
/// <summary>
/// 执行cmd命令
/// </summary>
/// <param name="cmd">需要执行的命令</param>
/// <returns></returns>
public string RumCmd(string cmd)
{
string str = null;
p.StartInfo.CreateNoWindow =true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");
p.WaitForExit();
str = p.StandardOutput.ReadToEnd();
p.Close();
return str;
}
/// <summary>
/// 通过CMD打开软件并执行相应命令
/// </summary>
/// <param name="programName"> 软件URL(.exe文件)</param>
/// <param name="cmd">需要进行的操作</param>
public void RunProgram(string programName,string cmd)
{
Process proc = new Process();