20 lines
676 B
Python
20 lines
676 B
Python
|
|
from flask import Flask, request, jsonify, send_from_directory
|
||
|
|
import subprocess
|
||
|
|
import random
|
||
|
|
|
||
|
|
app = Flask(__name__)
|
||
|
|
|
||
|
|
@app.route("/<path:path>")
|
||
|
|
def get_site(path):
|
||
|
|
return send_from_directory('static', path)
|
||
|
|
|
||
|
|
@app.post('/runProgram')
|
||
|
|
def run_program():
|
||
|
|
filename = "/tmp/program-" + str(random.randint(0,10000)) + ".grnd"
|
||
|
|
print(request.get_data(as_text=True))
|
||
|
|
with open(filename, "wt") as file:
|
||
|
|
file.write(request.get_data(as_text=True).replace("\\n", "\n"))
|
||
|
|
result = subprocess.run(["ground", filename], capture_output = True, text = True)
|
||
|
|
return jsonify({"stdout": result.stdout, "stderr": result.stderr, "exitCode": result.returncode})
|
||
|
|
|