I'm trying to do something for a project that I cannot find the answer to after searching and trying some different code.
What I'm trying to do is receive a string from a client(sent through via post, and I have to use this method, teacher's orders), and then compile this string using exec() in php file. Basically I'm "grading" a python code snippet sent to me as a string. I'm also doing this on the Andrew file system server(afs).
I'm not very experienced with python, mostly used other languages, but I'm able to make a python executable with php exec and also just compile it using cython(it's what the linux machines on our school have, not sure if I should use this). I got this to work with files.
My problem is I can't simply compile a string without running it. I can do
python -c "print('Hello World')"
python -m py_compile -c "print('Hello World')"
You can use the parser-Module. Write a script like this:
import sys import parser data = sys.argv try: parser.suite(data) except SyntaxError as e: print(e)
Invoke like this
python3.6 /tmp/test.py "import math"