terminal / app.py
root
Add application file
ed9a284
raw
history blame
679 Bytes
import subprocess
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/execute', methods=['POST'])
def execute_command():
data = request.json
command = data.get('command')
if not command:
return jsonify({"error": "No command provided"}), 400
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return jsonify({
"stdout": result.stdout,
"stderr": result.stderr,
"returncode": result.returncode
})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)