0
我正在使用此代碼將兩個數字作爲輸入傳遞給通過asp.net的C程序文件的.exe,之後嘗試從控制檯讀取輸出。我有問題要閱讀控制檯的任何輸出。 我的asp.net代碼是。通過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;
}
我有問題從控制檯讀取任何輸出。
入住這http://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output – malkam 2014-08-31 10:33:35
我以前嘗試過了,它不工作 – 2014-08-31 18:09:02