4 ms·
Do you have any links to examples of what it is really for? I've had a hard time finding code examples because the reasons listed at the bottom of the article.
by robertelder 10y ago
Do you have any links to examples of what it is really for? I've had a hard time finding code examples because the reasons listed at the bottom of the article.
- dekhn 10y agoSure, let's say you want to remotely control a Cisco router with a serial interface. expect makes it really easy to remotely connect to the serial interface, wait for a prompt, send a command, and take a conditional action that depends on the response.
- robertelder 10y agoI was thinking more of code examples. Expect is capable of doing much more than just the basic 'expect', then 'send' pattern. For example, this article: 'Most programmers don't know what Expect can do for them' http://wiki.tcl.tk/3913 http://wiki.tcl.tk/3913
- lilyball 10y agoThe article mentioned it's used for testing gcc and LLVM. If you want an example you can actually look at, it's also used for testing the fish-shell (fish-shell has other tests too, but expect is specifically used to actually test user-visible behavior, which makes expect the perfect tool for the task). You can find those tests in https://github.com/fish-shell/fish-shell/tree/master/tests https://github.com/fish-shell/fish-shell/tree/master/tests. The files of the form "foo.expect" are the tests (the "foo.expect.err" and "foo.expect.out" files are how it interacts with the rest of the testing infrastructure), and the file interactive.expect.rc provides a bunch of helper functions for the expect scripts, and in particular a standard way of looking for prompts (because the shell will redraw the prompt at various times, this function, coupled with the fish code in interactive.config, lets the expect scripts tell when it's the old prompt redrawn versus the new prompt after a command has been executed).
- deleted 10y ago[deleted]