C# 通过asp.net从控制台读取输出
我使用这段代码通过asp.net将两个数字作为输入传递给C程序文件的.exe,然后尝试从控制台读取输出。我无法从控制台读取任何输出。 我的asp.net代码是C# 通过asp.net从控制台读取输出,c#,c++,asp.net,c,C#,C++,Asp.net,C,我使用这段代码通过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.Fi
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代码,am向其传递输入
#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;
}
#包括
int main()
{
INTA、b、c;
printf(“输入两个要添加的数字”);
scanf(“%d%d”、&a和&b);
c=a+b;
printf(“输入的数字之和=%d\n”,c);
返回0;
}
我无法从控制台读取任何输出。使用
标准输入
,而不是使用发送键
StreamWriter sw = p.StandardInput;
sw.WriteLine("1");
sw.WriteLine("2");
sw.Close();
检查这个,我以前试过,但它不起作用
p.WaitForExit();
p.Close();
System.IO.StreamWriter file = new System.IO.StreamWriter(".\\out.txt");//Simplified
file.WriteLine(returnvalue);
file.Close();