Spaces:
Configuration error
Configuration error
File size: 597 Bytes
ea7fd90 |
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 |
"""
app.py
------
Flask server to handle command execution requests.
"""
from flask import Flask, request, jsonify
import subprocess
app = Flask(__name__)
@app.route("/execute", methods=["POST"])
def execute():
data = request.json
script = data["script"]
with open("temp_script.sh", "w") as file:
file.write(script)
subprocess.run(["chmod", "+x", "temp_script.sh"])
result = subprocess.run(["./temp_script.sh"], capture_output=True, text=True)
return jsonify({"output": result.stdout, "error": result.stderr})
if __name__ == "__main__":
app.run(port=5000)
|