Grading Program - Compile/executing C++ code withi

2020-02-13 04:53发布

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 allows 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?

标签: c++
2条回答
▲ chillily
2楼-- · 2020-02-13 05:05

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?

查看更多
太酷不给撩
3楼-- · 2020-02-13 05:06

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.

查看更多
登录 后发表回答