一、Asp.net后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Process pro = new Process();
//不显示窗口
pro.StartInfo.CreateNoWindow = true ;
pro.StartInfo.UseShellExecute = false;
//要调用的控制台程序
pro.StartInfo.FileName=@"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe";
//给控制台程序的参数传递值
pro.StartInfo.Arguments = this.txtValue.Text.Trim();
pro.Start();
//调用控制台程序的返回值
int i = pro.ExitCode;
Response.Write(i.ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
二、控制台应用程序代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int Main(string[] args)
{
int value = 0;
if (args[0] == "a")
value = 1;
else if (args[0] == "b")
value =2;
return value;
}
}
}