一个可以编译和检查源程序输出的C#应用​​程序 [英] A C# application which can compile and check the output of source program

查看:90
本文介绍了一个可以编译和检查源程序输出的C#应用​​程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何编写一个可视的C#应用​​程序,该应用程序可以编译和检查用户给出的简单源程序的输出.

例如,为用户提供了给定场景的样本输入和样本输出,并且要求他为其编写代码(在C ++中),并且应用程序应检查代码产生的输出是否与所需的输出匹配对于这种情况.

我怎么能做到这一点.是否可以将C ++编译器导入我们的应用程序.
请帮助解决这个问题...

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...

推荐答案

据我所知,输出意味着将文本输出到控制台(如果它是太文件的话,它的琐碎,在其他地方,这是不确定的);您只需要在C#应用程序的控制下运行一些编写到控制台的应用程序,并将输出与一些预设数据进行比较即可.

是出于教学目的吗?

OK,要做到这一点,您需要使用System.Diagnostics.Process.Start运行应用程序,将输出重定向到应用程序提供的某些流.

我在过去的解决方案中说明了如何进行此类重定向:
如何从命令提示符下阅读 [如何使用缓冲区(管道)读取控制台输出 [ ^ ].

—SA
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


如果我理解您的要求,就是要检查给定输入的正确输出.我想知道是否真的需要为此目的集成编译器.

您最好以这样的方式指定应用程序:它从文本文件读取输入,然后将输出写入另一个文件.

执行后,您要做的就是将输出文件与参考文件进行比较,并检测出任何差异.

文件比较实用程序比比皆是.

如果您的问题是有关如何自动执行检查过程的,则可以使用.NET应用程序或使用PowerShell编写脚本.
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.


使用CSharpCodeProvider ^ ]以编程方式编译代码.
Use the CSharpCodeProvider class[^] to compile your code programtically.


这篇关于一个可以编译和检查源程序输出的C#应用​​程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆