我在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文件中时,它会显示在文本框中。如何在文本框中显示返回值?
答案 0 :(得分:0)
使用Process类的ExitCode属性。见https://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode(v=vs.110).aspx