[HN Gopher] Miniexpect - A very simple expect-like library
___________________________________________________________________
Miniexpect - A very simple expect-like library
Author : rwmj
Score : 72 points
Date : 2022-07-26 09:32 UTC (13 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| rwmj wrote:
| Example showing how to use this library to ssh to a remote
| machine with a password and send a command:
|
| https://github.com/rwmjones/miniexpect/blob/master/example-s...
|
| I think the library is quite elegant because it essentially does
| very little itself. It's implemented almost entirely using the
| "partial match" feature of PCRE:
| https://pcre.org/current/doc/html/pcre2partial.html This means it
| can use the super-powerful regexps in PCRE, while itself being
| only a few hundred lines of code.
|
| This library has been used for years (since 2014) to do physical
| to virtual machine conversions, specifically for connecting from
| the physical machine to the remote hypervisor and automating
| virt-v2v:
| https://github.com/libguestfs/virt-p2v/blob/master/virt-p2v....
| https://github.com/libguestfs/virt-p2v/blob/master/ssh.c
| kubb wrote:
| What's the reason behind writing automation tooling in C
| instead of higher level languages? The usual (portability,
| performance) don't seem to apply at first glance.
| rwmj wrote:
| Because the program it's used in is written in C too, as is
| most software that runs on Unix-like systems. It uses and
| depends on another C library (PCRE). The P2V system has to
| fit on a small bootable ISO, so minimising code size and
| dependencies is an overriding concern. Also it was written in
| 2014.
| sim7c00 wrote:
| love it, only knew expect from python, so quite happy to
| find a c library :D thanks!! (stubborn person who would
| write a website in C here!!)
| mkovach wrote:
| My thoughts exactly. I love using expect, but why would I
| write a C program when I quick and simple TCL script (expect
| is build with TCL and is threaded and easy to make thread-
| safe scripts).
|
| There are also expect clones in Python and Perl (probably
| others, but I know and have used those both) if TCL is an
| issue for you.
|
| This looks nice, but I don't see if as very useful.
| phoboslab wrote:
| This repo says how it relates to other implementations but
| curiously fails to mention what "expect" actually is.
|
| So for everyone as ignorant as myself, I guess it's referring to
| this[1]:
|
| > Expect is a tool for automating interactive applications such
| as telnet, ftp, passwd, fsck, rlogin, tip, etc.
|
| [1] https://core.tcl-lang.org/expect/index
| pid-1 wrote:
| As an intern, I used expect in my first job to create a
| monitoring system for ~ 200 L3 Routers in a private network.
| Eventually I learned about SNMP and also that I probably should
| Google "How to X" before rolling out my own solution for
| anything.
| RHSeeger wrote:
| Interestingly, I did something very similar in my first job,
| though it included backing up configurations and the like.
| It's worth noting that a lot of routers (at that time) didn't
| really support much in the way of SNMP. As such, one had to
| navigate menus to get to the necessary options; and nothing
| is as potent as Expect at that kind of thing.
| masukomi wrote:
| thanks. i was assuming it was some sort of unit testing thing.
| "expect" foo to equal bar kinda stuff.
| rwmj wrote:
| Thanks for the feedback - I've updated the README file.
| shric wrote:
| It used to be hosted by https://nist.gov/ at expect.nist.gov
|
| Here is it in 1997, it hasn't changed much.
|
| https://web.archive.org/web/19971210131642/http://expect.nis...
| aidenn0 wrote:
| I won't lie, I've used the original expect just because I needed
| to force a program to run in a pty. It turns out that script(1)
| will also do this though.
| imurray wrote:
| I used to use `unbuffer` which comes with expect, and might be
| what you used too. I now use the following hack, which works
| faster:
|
| Create isatty.so like this: echo "int
| isatty(int fd) { return 1; }" | gcc -O2 -fpic -shared -ldl -o
| isatty.so -xc -
|
| Then to make `some_program` think it's in a tty:
| LD_PRELOAD=./isatty.so some_programe
|
| Source and more:
| https://unix.stackexchange.com/questions/249723/how-to-trick...
| efitz wrote:
| rwmj wrote:
| It's LGPLv2+ which doesn't restrict your use in any way -- you
| can combine it with proprietary code, ship it in closed source
| products etc -- but does mean that you must contribute changes
| (to this library code only) back rather than being able to
| steal them from the commons for your proprietary benefit.
| neoromantique wrote:
| Good.
| Brian_K_White wrote:
| It's a cool unnamed product you work on, but being proprietary
| means that it's useless for any project I've ever worked on.
|
| Did you actually think that anyone could possibly sympathize
| with a complaint about the intolerability of reciprocity?
|
| Whatever product you're working on, if it can't include any gpl
| code, then it means they give you money instead. Do you hear
| yourself? "Boo hoo I can't take without giving" ?
|
| Or are you claiming that you have only ever worked on MIT
| projects?
| commonlisper wrote:
| No license is going to be suitable for everyone. You might
| think BSD, MIT, WTFPL are the most liberal licenses but they
| are not suitable for me. If I am invested in an open source
| software enough to contribute code to it then I want that when
| a greedy company takes that software and improves it and
| redistributes it they are also forced to release the source
| code benefitting everyone. BSD, MIT, WTFPL can't do that but
| GPL can. No license is a silver bullet.
| aaaaaaaaaaab wrote:
| You're free to contact the author to pay for a commercial
| license for your projects.
| inops wrote:
| It's LGPL
___________________________________________________________________
(page generated 2022-07-26 23:02 UTC)