Add TERM env and debug output to troubleshoot PTY

parent c873efa0
......@@ -193,30 +193,38 @@ def connect_terminal(client_id):
stdin=slave,
stdout=slave,
stderr=slave,
preexec_fn=os.setsid
preexec_fn=os.setsid,
env=dict(os.environ, TERM='xterm')
)
os.close(slave)
# Start a thread to read output
output_buffer = []
def read_output():
output_buffer.append(f'Process PID: {proc.pid}\r\n')
while proc.poll() is None:
r, w, e = select.select([master], [], [], 0.1)
if master in r:
try:
data = os.read(master, 1024)
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:
break
# Read any remaining data
try:
data = os.read(master, 1024)
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)
except:
pass
output_buffer.append('\r\nProcess finished.\r\n')
os.close(master)
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