Update app/main.py
Browse files- app/main.py +11 -6
app/main.py
CHANGED
@@ -14,16 +14,21 @@ def index():
|
|
14 |
@socketio.on('input', namespace='/terminal')
|
15 |
def handle_input(data):
|
16 |
command = data['command']
|
17 |
-
print(f"Received command: {command}")
|
18 |
result = execute_command(command)
|
19 |
emit('output', {'output': result})
|
20 |
|
21 |
def execute_command(command):
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if __name__ == '__main__':
|
29 |
socketio.run(app, host='0.0.0.0', port=7860)
|
|
|
14 |
@socketio.on('input', namespace='/terminal')
|
15 |
def handle_input(data):
|
16 |
command = data['command']
|
17 |
+
print(f"Received command: {command}") # Debugging log
|
18 |
result = execute_command(command)
|
19 |
emit('output', {'output': result})
|
20 |
|
21 |
def execute_command(command):
|
22 |
+
try:
|
23 |
+
result = subprocess.run(['docker', 'exec', 'terminal-website_ubuntu_1', 'bash', '-c', command],
|
24 |
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
|
25 |
+
output = result.stdout.decode('utf-8') + result.stderr.decode('utf-8')
|
26 |
+
print(f"Command output: {output}") # Debugging log
|
27 |
+
return output
|
28 |
+
except subprocess.CalledProcessError as e:
|
29 |
+
error_output = e.stdout.decode('utf-8') + e.stderr.decode('utf-8')
|
30 |
+
print(f"Command error: {error_output}") # Debugging log
|
31 |
+
return error_output
|
32 |
|
33 |
if __name__ == '__main__':
|
34 |
socketio.run(app, host='0.0.0.0', port=7860)
|