Grading Program - Compile/executing C++ code within C++
I am writing a program to grade C++ code that students submit. Right now it uses a system call to compile every source file then redirects the input to a file and calls the new executables in processes and searches the output for certain strings. This also allow开发者_StackOverflows me to have a timeout on processes for programs that crash.
Is there a better way to do this than a system call? Or a better way to do this in general?
You may want to run the programs under an alternate account, e.g. ssh with key-based authentication is a good way to switch to a dummy account.
If any of the assignments require user interaction, then expect
(which is Tcl-based) would be a good choice.
I can't think of other way in C/C++ to run an external executable without using a system call (directly or indirectly).
You may consider using Perl/Python instead of coding C++ to do such checking/automation.
EDIT:
Since you started scripting in Perl, you may want to look at:
http://perldoc.perl.org/functions/exec.html
http://perldoc.perl.org/Shell.html
http://perldoc.perl.org/functions/system.html
http://www.perlmonks.org/?node_id=78523
How can I run a system command in Perl asynchronously?
How can I terminate a system command with alarm in Perl?
精彩评论