Reading output from console through asp.net
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.
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);
My C code to which am passing inputs is.
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.
Re: Reading output from console through asp.net
Perhaps it's a permissions issue. Or it might be the account asp.net runs under can't access the console. Try piping the output of the exe to a file and then read the file.
Re: Reading output from console through asp.net
Quote:
I am having problem to read any output from the console.
What problems are you having?
I don't see any error checking in your asp.net code?
Re: Reading output from console through asp.net
Quote:
Originally Posted by
2kaud
I don't see any error checking in your asp.net code?
Whenever i run my program it opens the .exe file of the C program and pass the in put through sendkeys
now i want to read all of that output from the console of the C program but its not working
Re: Reading output from console through asp.net
Quote:
Originally Posted by
hussainahmad007
Whenever i run my program it opens the .exe file of the C program and pass the in put through sendkeys
now i want to read all of that output from the console of the C program but its not working
In what way is it not working? Do you get any errors reported?
Re: Reading output from console through asp.net
Sorry to say, but using send keys with a console app isn't the most reliable approach even under the best circumstances.
That being said, did you read my first response? Did that make sense?