c# 调用cmd及参数
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Web;
namespace WebApplication2
{
/// <summary>
/// runexe 的摘要说明
/// </summary>
public class runexe : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
try
{
//string exe_path = "D:\\dll\\test_dll6\\test_dll\\test_dll.exe"; // 被调exe
//string[] the_args = { "D:\\dll\\test_dll6\\test_dll\\input.txt" }; // 被调exe接受的参数
string exe_path = ConfigurationManager.AppSettings["exe"].ToString();
string[] the_args = ConfigurationManager.AppSettings["args"].ToString().Split(';');
StartProcess(exe_path, the_args);
context.Response.Write("Hello World");
}
catch (Exception ex)
{
throw;
}
}
// 调用exe的函数
public bool StartProcess(string runFilePath, params string[] args)
{
string s = "";
foreach (string arg in args)
{
s = s + arg + " ";
}
s = s.Trim();
Process process = new Process();//创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo(runFilePath, s); // 括号里是(程序名,参数)
process.StartInfo = startInfo;
process.Start();
return true;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}