Add debug output for wsssh process startup and output reading

parent a6b05ef7
...@@ -195,9 +195,10 @@ def connect_terminal(client_id): ...@@ -195,9 +195,10 @@ def connect_terminal(client_id):
# Start a thread to read output # Start a thread to read output
output_buffer = [] output_buffer = []
def read_output(): def read_output():
output_buffer.append('Process started, reading output...\r\n')
while proc.poll() is None: while proc.poll() is None:
try: try:
data = proc.stdout.read(1024) data = proc.stdout.read(1) # Read byte by byte for real-time
if data: if data:
output_buffer.append(data.decode('utf-8', errors='ignore')) output_buffer.append(data.decode('utf-8', errors='ignore'))
except: except:
...@@ -209,10 +210,13 @@ def connect_terminal(client_id): ...@@ -209,10 +210,13 @@ def connect_terminal(client_id):
output_buffer.append(data.decode('utf-8', errors='ignore')) output_buffer.append(data.decode('utf-8', errors='ignore'))
except: except:
pass pass
output_buffer.append('\r\nProcess finished.\r\n')
thread = threading.Thread(target=read_output, daemon=True) thread = threading.Thread(target=read_output, daemon=True)
thread.start() thread.start()
if proc.poll() is not None:
output_buffer.append(f'\r\nProcess failed to start, exit code: {proc.returncode}\r\n')
active_terminals[request_id] = {'client_id': client_id, 'username': username, 'proc': proc, 'output_buffer': output_buffer} active_terminals[request_id] = {'client_id': client_id, 'username': username, 'proc': proc, 'output_buffer': output_buffer}
return jsonify({'request_id': request_id, 'command': ' '.join(command)}) return jsonify({'request_id': request_id, 'command': ' '.join(command)})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment