-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (32 loc) · 1.46 KB
/
app.py
File metadata and controls
41 lines (32 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask, render_template, request
import subprocess
app = Flask(__name__, static_url_path='/static')
@app.route('/python', methods=['GET', 'POST'])
def index_python():
if request.method == 'POST':
code = request.form['code.py']
try:
# Compila y ejecuta el código Python
result = subprocess.check_output(['python', '-c', code], stderr=subprocess.STDOUT, text=True)
except subprocess.CalledProcessError as e:
result = e.output
return render_template('indexPy.html', code=code, result=result)
return render_template('indexPy.html', code='', result='')
@app.route('/cpp', methods=['GET', 'POST'])
def index_cpp():
if request.method == 'POST':
code = request.form['code.cpp']
try:
# Guarda el código en un archivo temporal
with open('temp.cpp', 'w') as file:
file.write(code)
# Compila el código C++
subprocess.check_output(['g++', 'temp.cpp', '-o', 'temp'], stderr=subprocess.STDOUT)
# Ejecuta el programa compilado
result = subprocess.check_output(['./temp'], stderr=subprocess.STDOUT, text=True)
except subprocess.CalledProcessError as e:
result = e.output
return render_template('indexC.html', code=code, result=result)
return render_template('indexC.html', code='', result='')
if __name__ == '__main__':
app.run(debug=True)