-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (24 loc) · 818 Bytes
/
app.py
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
from flask import Flask, request, jsonify, render_template
import subprocess
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/schedule', methods=['POST'])
def schedule():
data = request.json
jobs = data['jobs']
input_file = 'input.txt'
output_file = 'output.txt'
# Write the job data to input.txt
with open(input_file, 'w') as f:
for job in jobs:
f.write(f"{job['id']} {job['burst']} {job['arrival']}\n")
# Run the C++ scheduling program
subprocess.run(['./main'], check=True)
# Read the output file
with open(output_file, 'r') as f:
output_data = f.read()
return jsonify({'output': output_data})
if __name__ == '__main__':
app.run(debug=True)