-
August 31st, 2014, 04:19 PM
#1
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.
-
August 31st, 2014, 08:33 PM
#2
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.
-
September 1st, 2014, 02:43 AM
#3
Re: Reading output from console through asp.net
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?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 1st, 2014, 04:08 AM
#4
Re: Reading output from console through asp.net
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
-
September 1st, 2014, 04:33 AM
#5
Re: Reading output from console through asp.net
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?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 1st, 2014, 02:42 PM
#6
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?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|