Re:Most programmers don't know what Expect can do for them
by mzs on Sunday September 08, 2019 @02:01AM
(#20908863)
I wish there was something like expect that was like, "ok I've done what I needed to init, now get out of the way." I've always had to create a loop that just reads and writes everything eventually. Maybe I could ldpreload a tcl interpreter and change some pointers but yikes.
[ Parent
| on HN ]
Re:Most programmers don't know what Expect can do for them
by _ph_ on Sunday September 08, 2019 @04:37AM
(#20909297)
Isn't that what interact is meant to do?
Re:Most programmers don't know what Expect can do for them
by jraph on Sunday September 08, 2019 @04:42AM
(#20909312)
If I understood correctly, you may be able to do that using pexpect and the interact method.
import struct, fcntl, termios, signal, sys
def sigwinch_passthrough (sig, data):
s = struct.pack("HHHH", 0, 0, 0, 0)
a = struct.unpack('hhhh', fcntl.ioctl(sys.stdout.fileno(),
termios.TIOCGWINSZ , s))
if not child.closed:
child.setwinsize(a[0],a[1])
child = pexpect.spawnu("sh", args, encoding='utf-8', logfile=sys.stdout)
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
child.expect_exact("...")
child.logfile = None # Otherwise, interact raises an Exception
child.send("...\n")
child.interact()