Jian Wen added the comment:
The following code shows how to use pts.
#!/usr/bin/env python
import os
import pty
import shlex
import time
_args = "/usr/bin/ssh example.com"
args = shlex.split(_args)
pid, child_fd = pty.fork()
if pid == 0:
# Child
os.execv("/usr/bin/ssh", args)
else:
Ross Lagerwall added the comment:
This appears to be a buffering issue with the tr program. Replace with ["cat",
"-"] and it works whether the close() is in or not.
To fix this, you need to open up the child process so that it is connected to a
tty. man 4 pts if you want to investigate this f
New submission from Andrew Moffat :
The following code only works if the "p.stdin.close()" line is uncommented. It
seems that stdin only flushes to the process on stdin.close(), not on
stdin.flush().
---
import subprocess as subp
import threading
import time