【发布时间】:2014-08-31 10:04:24
【问题描述】:
我正在使用此代码通过 asp.net 将两个数字作为输入传递给 C 程序文件的 .exe,然后尝试从控制台读取输出。我在从控制台读取任何输出时遇到问题。 我的asp.net代码是。
string returnvalue;
Process p = new Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.FileName = ("C:\\Users\\...\\noname01.exe");
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
Thread.Sleep(500);
SendKeys.SendWait("1");
Thread.Sleep(500);
SendKeys.SendWait("~");
Thread.Sleep(500);
SendKeys.SendWait("2");
Thread.Sleep(500);
SendKeys.SendWait("~");
Thread.Sleep(500);
StreamReader sr = p.StandardOutput;
returnvalue = sr.ReadToEnd();
System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\...\\StudentOutput.txt");
file.WriteLine(returnvalue);
传递输入的我的 C 代码是。
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter two numbers to add\n");
scanf("%d%d",&a,&b);
c = a + b;
printf("Sum of entered numbers = %d\n",c);
return 0;
}
我无法从控制台读取任何输出。
【问题讨论】:
-
我已经试过了,但它不起作用