- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
19 lines (17 loc) · 602 Bytes
/
Copy pathapp.py
File metadata and controls
19 lines (17 loc) · 602 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fromflaskimportFlask, jsonify, request
fromflask_corsimportCORS
fromsubprocessimportPopen, PIPE
importsys
importos
app=Flask(__name__)
cors=CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/', methods=['POST'])
defindex():
content=request.get_json()
print(content)
withopen(content['filename'], 'w') asoutfile:
outfile.write(content['content'])
p=Popen([sys.executable, content['filename']], stdout=PIPE, stderr=PIPE, universal_newlines=True)
output, err=p.communicate()
os.remove(content['filename'])
returnjsonify({"output": output, "err": err})