こんにちは、私はttyに住み、入力と出力をフィルタリングする2番目のttyを生成できる疑似端末を書いています
私は今のところPythonで書いています.2番目のttyを生成し、読み書きは簡単です
しかし、私が読んだとき、読み取りは終了せず、さらに入力を待ちます。
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
----------------------------- 出力 -------------------- ----
intty $ python intty.py
'intty.py'
'testA_blank'
'testB_blank'
(hangs here does not return)
バッファの終わりに達しているように見え、 None または '' を返す代わりに、次の入力を待ってハングします。
出力が完了したかどうかを確認するには、何を探す必要がありますか? バッファの終わり?印刷できない文字?
- - - - - - - - 編集 - - - - - - -
これは、ls の代わりに xpcshell を実行したときにも発生します。これらの対話型プログラムには、プロンプトを再度表示する方法があると想定しています。不思議なことに、プロンプトです。この場合、「js>」は表示されません。