File size: 716 Bytes
22614e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed0b61e
 
 
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
import os
import pexpect
from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)

socketio = SocketIO(app)

@app.route('/')
def index():
    return render_template('index.html')

@socketio.on('command')
def handle_command(command):
    output = run_command(command)
    emit('output', output)

def run_command(command):
    child = pexpect.spawn(command)
    child.timeout = 5  # Set a timeout for the command (adjust as needed)
    try:
        child.expect(pexpect.EOF)
        return child.before.decode('utf-8')
    except pexpect.exceptions.TIMEOUT:
        return 'Command timed out.'


print("running")
socketio.run(app, port=7860,allow_unsafe_werkzeug=True)