Most programmers don't know what Expect can do for them
wiki.tcl-lang.org
wiki.tcl-lang.org
Yes, wrapping a telnet session is a hack... But it was a hell of a hack that did everything we needed!
Backed by pexpect of course.
I used to think that knowing Tcl was a kind of super power. It was incredibly productive. It was far better for quick scripting than either bash or awk - but large programs could get somewhat unmanageable.
It would be great to see a renaissance of TCL usage, though I’d be pretty much re-learning it today.
I'm afraid I don't share your fondness for it. :)
Quite recently I was working on some python that used netmiko, which is similar but more ssh-oriented.
Having used both, I don’t know when I’d ever use expect. Maybe if there was no python available for some reason.
The developer ergonomics on netmiko are just better. It’s not anything about python vs tcl, it’s that netmiko “does more out of the box”, and expect is a bit lower-level.
http://code.activestate.com/recipes/440554-module-to-allow-a... https://www.python.org/dev/peps/pep-3145/
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()Just in the past week, I've heard tcl, ruby, perl, and java all declared dead. Oh well. Internet comments are cheap and meaningless.
I wish I had a concrete example to share so someone here could confirm, but like I said, it was some years ago.
[1] https://ruby-doc.org/stdlib-2.6.4/libdoc/pty/rdoc/IO.html#M0...
So more people use expect than know it.
The issue I feel is that it's flimsy to wait for some expected output. I mean, it's even in the name! Especially when working with unknown APIs like Cisco IOS CLI.
So whenever I've done manual expect coding I've always felt very much out of my element and out of control. I am a control freak btw.
It works while it works but as soon as something unexpected happens it all goes to sh*t.
The output of a terminal is just simply too unstructured to work in any high reliability environment.
Sitting at a root shell executing untested or uncertain things is pretty high on the list of don't do these things.