Visual Basic with Mono and Jobe

Re: Visual Basic with Mono and Jobe

de Richard Lobb -
Número de respuestas: 0

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