I am using this code to pass two numbers as input to an .exe of a C program file through asp.net and after that trying to read the output from console. I am having problem to read any output from the console. My asp.net code is.
My C code to which am passing inputs is.Code: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);
Code:#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; }
I am having problem to read any output from the console.




Reply With Quote
