Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to know how to write a visual C# application which compiles and checks output of a simple source program given by user.

For example the user is supplied with the sample input, and sample output for a given scenario, and he is required to write the code for it (in C++) and the application should check if the output produced by the code matches with the output required for that scenario.

How can i achieve this. is it possible to import C++ compiler to our application.
Please help on this question...
Posted

As I understand it, the output means output the text to console (if it's is too file, it's trivial, is somewhere else, it would be uncertain); you only need to run some application writing to console under control of your C# application and compare output with some preset data.

Is it for teaching purposes?

OK, to do it, you need to run your application using System.Diagnostics.Process.Start redirecting the output the some stream supplied by your application.

I explained how to do such redirection in my past solutions:
How to read from command prompt[^],
How to read console output with buffer (pipe)[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 10-Aug-11 7:01am    
Nice reply, my 5
Sergey Alexandrovich Kryukov 10-Aug-11 15:25pm    
Thank you, Espen.
--SA
If I understand you, the request is to check correct output for a given input. I wonder there is a real need to integrate the compiler for this purpose.

You'd better specify the application in such a way that it reads input from a text file and writes output to another one.

After execution, all you need to do is to compare the output file to a reference file and detect any difference.

File comparison utilities abound.

If your question is about how to automate the checking process, you could do the scripting with a .NET application or using PowerShell.
 
Share this answer
 
v2
Comments
VigneshPT 9-Aug-11 9:28am    
u mean there is no need to integrate the compiler?? and i've kind of figured out how to create executable file for the code given by user after compiling, but i want to know how i can write the output of the executing code to a file..
YvesDaoust 9-Aug-11 9:53am    
The application under test should do it. Put that requirement in the application specs.

Capturing the output of an existing application is rarely doable.
Use the CSharpCodeProvider class[^] to compile your code programtically.
 
Share this answer
 
Comments
VigneshPT 9-Aug-11 8:51am    
thanx.. its kind of what i was looking for.. i read the article which u refered. i would also like to know how to programatically write the output produced by the code to a file..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900