Spaces:
Configuration error
Configuration error
""" | |
app.py | |
------ | |
Flask server to handle command execution requests. | |
""" | |
from flask import Flask, request, jsonify | |
import subprocess | |
app = Flask(__name__) | |
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) | |