Add TERM env and debug output to troubleshoot PTY

parent c873efa0
...@@ -193,30 +193,38 @@ def connect_terminal(client_id): ...@@ -193,30 +193,38 @@ def connect_terminal(client_id):
stdin=slave, stdin=slave,
stdout=slave, stdout=slave,
stderr=slave, stderr=slave,
preexec_fn=os.setsid preexec_fn=os.setsid,
env=dict(os.environ, TERM='xterm')
) )
os.close(slave) os.close(slave)
# 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(f'Process PID: {proc.pid}\r\n')
while proc.poll() is None: while proc.poll() is None:
r, w, e = select.select([master], [], [], 0.1) r, w, e = select.select([master], [], [], 0.1)
if master in r: if master in r:
try: try:
data = os.read(master, 1024) data = os.read(master, 1024)
if data: if data:
output_buffer.append(data.decode('utf-8', errors='ignore')) decoded = data.decode('utf-8', errors='ignore')
output_buffer.append(decoded)
# Debug: print to server log
print(f"Read data: {repr(decoded)}")
except: except:
break break
# Read any remaining data # Read any remaining data
try: try:
data = os.read(master, 1024) data = os.read(master, 1024)
while data: while data:
output_buffer.append(data.decode('utf-8', errors='ignore')) decoded = data.decode('utf-8', errors='ignore')
output_buffer.append(decoded)
print(f"Read remaining: {repr(decoded)}")
data = os.read(master, 1024) data = os.read(master, 1024)
except: except:
pass pass
output_buffer.append('\r\nProcess finished.\r\n')
os.close(master) os.close(master)
thread = threading.Thread(target=read_output, daemon=True) thread = threading.Thread(target=read_output, daemon=True)
......
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