Hello Richard
I've been using coderunner with questions in python, java, C and Cpp for a while, but now I would like to be able to use it also with C# since it is now completely cross plateform
But I have been trying to create a coderunner question with C# for the last few days and even though I feel I'm almost there, I'm stuck with an error that I can't find a solution to.
I successfully installed the jobeserver a few years back thanks to your video step-by-step but I have only some basic knowledge of Linux and its commands and I guess that is why I'm having difficulties to find the solution (which I hope will be obvious to you ;) )
To summarize what I've done :
- I have dowloaded and installed the dotnet sdk,
- I have given jobe00 enough rights to use it (I have not found yet how to make the dotnet usable by any user on the server)
- I wrote a python script that creates a csproj file and a simple cs file and compiles the program
- I logged to the server, I did "su jobe00" and was able to run the script successfully (it compiles the program and runs it)
- I created a cs_program question prototype (I added the following at the end of builtin_PROTOTYPES.xml in coderunner/db and I uploaded this xml throuh moodle), and I used the content of the script (I just modified the variable "student_answer" to get the content of the moodle answer box)
(I also added a CS_Task.php in jobehome/application, but I'm not sure if I did it right and even less that it is being used (since I have my sandbox in python3))
BUILT_IN_PROTOTYPE_cs_programBuilt-in prototypes are documented in the language strings.1.00000000.00000000cs_program10000181001<br />
""" The template for a question type that compiles and runs a student-submitted mono C# program. """<br />
<br />
import subprocess, sys, os<br />
<br />
# Write the student code to a file prog.cs please<br />
student_answer = """{{ STUDENT_ANSWER | e('py') }}"""<br />
<br />
with open("test.csproj","w") as projsrc:<br />
print("""<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net7.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable></PropertyGroup></Project>""", file=projsrc)<br />
<br />
<br />
with open("prog.cs","w") as src:<br />
print(student_answer, file=src)<br />
<br />
# Compile <br />
return_code = subprocess.run("dotnet build", shell=True)<br />
<br />
try:<br />
subprocess.run(["./bin/Debug/net7.0/test"], universal_newlines=True, shell=True)<br />
except subprocess.CalledProcessError as e:<br />
if e.returncode > 0:<br />
# Ignore non-zero positive return codes<br />
if e.output:<br />
print(e.output)<br />
else:<br />
# But negative return codes are signals - abort<br />
if e.output:<br />
print(e.output, file=sys.stderr)<br />
if e.returncode < 0:<br />
print("Task failed with signal", -e.returncode, file=sys.stderr)<br />
print("** Further testing aborted **", file=sys.stderr)<br />
"""<br />
000pyton3csEqualityGrader{"linkargs": ["-lm"]}00ace
- When I click "Save Changes and continue editing", I see that it creates the csproj and cs files as intended (I just added "os.chdir('/home/jobe00/cs2')" at the beginning of my script to verify that the files were indeed created and were problem free)
- When I use the script manually, thoses files can be used to generate an executable that can be run without problem in the console (also through the script)
- But in moodle, through CodeRunner, neither the compilation command nor the run command work : both give me "File size limit exceeded (core dumped)"
I have tried to modify the MemLimit in the Sandbox Advance Customisation (because I also have encountered the memory limit error, but it does not seem to be problematic anymore), but the problem persist
I also changed the LanguageTask.php fil to increase some limits :
// Global default parameter values. Can be overridden by subclasses,
// and then further overridden by the individual run requests.
public $default_params = array(
'disklimit' => 200, // MB (for normal files)
'streamsize' => 20, // MB (for stdout/stderr)
'cputime' => 50, // secs
'memorylimit' => 2000, // MB
'numprocs' => 200,
'compileargs' => array(),
'linkargs' => array(),
'interpreterargs' => array(),
'runargs' => array()
);
// Global minima settings for runguard sandbox when compiling.
// These override the default and task specific settings when a task
// is compiling in the sense that the parameter value used cannot be
// less than the one specified here.
public $min_params_compile = array(
'disklimit' => 200, // MB
'cputime' => 20, // secs
'memorylimit' => 2000, // MB
'numprocs' => 50 // processes
);
[...........]
public function run_in_sandbox($wrappedCmd, $iscompile=true, $stdin=null) {
$filesize = 10000 * $this->getParam('disklimit', $iscompile); // MB -> kB
$streamsize = 10000 * $this->getParam('streamsize', $iscompile); // MB -> kB
$memsize = 10000 * $this->getParam('memorylimit', $iscompile);
$cputime = $this->getParam('cputime', $iscompile);
$killtime = 20 * $cputime; // Kill the job after twice the allowed cpu time
Since jobe00 has no issue (without the need of sudo (but for that I have added jobe00 to the liste of sudoer)) to run the dotnet build as well as the generated executable, whether it is manually or through a script, I am certain the solution is near, but I don't know what to do about this size issue. I've looked at your forum but I did not find the solution, this thread being the closest to my needs
I hope you will be able to help me, because coderunner is really a great tool and I really wish I could use it with C# :)
Thank you for your time and your help
Dominique