enemy7 commited on
Commit
22614e8
·
1 Parent(s): 2fb12bb

Create app,py

Browse files
Files changed (1) hide show
  1. app,py +29 -0
app,py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pexpect
3
+ from flask import Flask, render_template
4
+ from flask_socketio import SocketIO, emit
5
+
6
+ app = Flask(__name__)
7
+
8
+ socketio = SocketIO(app)
9
+
10
+ @app.route('/')
11
+ def index():
12
+ return render_template('index.html')
13
+
14
+ @socketio.on('command')
15
+ def handle_command(command):
16
+ output = run_command(command)
17
+ emit('output', output)
18
+
19
+ def run_command(command):
20
+ child = pexpect.spawn(command)
21
+ child.timeout = 5 # Set a timeout for the command (adjust as needed)
22
+ try:
23
+ child.expect(pexpect.EOF)
24
+ return child.before.decode('utf-8')
25
+ except pexpect.exceptions.TIMEOUT:
26
+ return 'Command timed out.'
27
+
28
+ if __name__ == '__main__':
29
+ socketio.run(app, port=7860)