使用asp.net运行可执行文件并显示其返回值

时间:2015-07-20 04:34:01

标签: c# c++ asp.net

我在cpp中创建了一个返回整数的.exe文件。我必须在asp.net的文本框中显示此返回值。 我的cpp代码在这里

#include <iostream>
using namespace std;

int addition (int a, int b)
{
     int r;
     r=a+b;
     return r;
}

int main ()
{
    int z;
    z = addition (5,3);
    //cout << "The result is " << z;
    return z;
 }

执行上面cpp的c#代码是,

protected void Button1_Click(object sender, EventArgs e)
{
   try
    {
        var path =Server.MapPath("~/cpp/sample1.exe");  
        ProcessStartInfo info = new ProcessStartInfo(path);  
        info.RedirectStandardOutput = true; 
        info.UseShellExecute = false; 
        p.Start(); // Send whatever was returned through the output to the   client.
        TextBox1.Text = p.StandardOutput.ReadToEnd();
    }
}

执行时,文本框不显示返回值。但是,当我将cout << "The result is " << z;放在cpp文件中时,它会显示在文本框中。如何在文本框中显示返回值?

1 个答案:

答案 0 :(得分:0)

相关问题