Visual Basic with Mono and Jobe

Visual Basic with Mono and Jobe

von A R -
Anzahl Antworten: 1

Hello Richard,

Firstly I think CodeRunner is fantastic, thank you for putting so much effort in to it.

I read your forum post https://coderunner.org.nz/mod/forum/discuss.php?d=79  relating to C# and managed to alter it to work for VB using the Mono.  The problem I am having is the vbnc mono compiler outputs some extra text during compilation which appears on the results window, a regular expression check allows the answer to be checked but it looks messy as you can see from the screen print below:




I have tried to use the 'quiet' command with mono's vbnc but it doesn't seem to be working.  Do you have any suggestions?


Any help would be much appreciated.

Thank you kindly
Als Antwort auf A R

Re: Visual Basic with Mono and Jobe

von Richard Lobb -

Hi Ashraf. All you have to do is capture all the subprocess output, including from the compile stage and filter out any junk before printing it. The following script seems to work for the Hello world example, but as I don't use VB I'm not sure how it behaves in various error situations. You will probably need to tune the script a bit, but the general principle should be OK.

""" The template for a question type that compiles and runs a student-submitted
    mono vb program.
"""

import subprocess, sys

# Write the student code to a file prog.vb
student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
with open("prog.vb", "w") as src:
    print(student_answer, file=src)

# Compile
ok = True
try:
    compile_output = subprocess.check_output(['vbnc', 'prog.vb'], universal_newlines=True)
except subprocess.CalledProcessError as e:
    print(e.output, file=sys.stderr)
    print("** Compilation failed. Testing aborted **", file=sys.stderr)
    ok = False
sys.stderr = ""
# If compile succeeded, run the code. Since this is a per-test template,
# stdin is already set up for the stdin text specified in the test case,
# so we can run the compiled program directly.
if ok:
    try:
        output = subprocess.check_output(["mono", "./prog.exe"], universal_newlines=True)
        print(output)
    except subprocess.CalledProcessError as e:
        if e.returncode > 0:
            # Ignore non-zero positive return codes
            if e.output:
                print(e.output)
        else:
            # But negative return codes are signals - abort
            if e.output:
                print(e.output, file=sys.stderr)
            if e.returncode << 0:
                print("Task failed with signal", -e.returncode, file=sys.stderr)
            print("** Further testing aborted **", file=sys.stderr)

 VB sample output