I am using fly machine to run student’s code in an alpine image. I have created a UI where they can upload their c++ code.
I have my admin area, where I can upload some helper files like shellscript and txt files which i use to compare student’s output to mine. Here is how my script looks.
#!/bin/bash
output=$(./executable 1 < input.txt)
expected_output=$(cat solution.txt)
if [ "$output" = "$expected_output" ]; then
state="pass"
else
state="fail"
fi
JSON_FMT='{"state": "%s", "output":"%s"}'
printf "$JSON_FMT" "$state" "$output"
using the rest api I make a POST req to container/machines/#{machine_id}/exec
with cmd: “sh ./shellscript.sh” and i get back (just an example)
{
"exit_code": 0,
"exit_signal": 0,
"stderr": "",
"stdout": "{\"state\": \"pass\", \"output\":\"1 33 55\n 55 77 88\n \"}"
}
as you can see, the stdout is not a valid json because of \n or linefeed. So in your opinion, how should i handle this case? Is there other way than sending json so that I can know the code passed the comparison and i can read the output?