Hi I'm writing a psudo-terminal that can live in a tty and spawn a second tty which is filters input and output from
I'm writing it in python for now, spawning the second tty and reading and writing is easy
but when I read, the read does not end, it waits for more input.
import subprocess
pfd = subprocess.Popen(['/bin/sh'], shell=True,
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
cmd = "ls"
pfd.stdin.write(cmd + '\n')
out = ''
while 1:
c = pfd.stdout.read(1)
if not c: # if end of output (this never happends)
break
if c == '\n': # print line when found
print repr(out)
out = ''
else:
out += c
----------------------------- outputs ------------------------
intty $ python intty.py
'intty.py'
'testA_blank'
'testB_blank'
(hangs here does not return)
it looks like it's reaching the end of hte buffer and instead of returning None or '' it hangs waiting for more input.
what should I be looking for to see if the output has completed? the end of the buffer? a non-printable character?
---------------- edit -------------
this happends also when I run xpcshell instead of ls, I'm assuming these interactive programs have some way of knowing to display the prompt again, strangly the prompt, in this case "js>" never apears