scripting "interactive" input

Chris Devers cdevers at pobox.com
Mon Nov 17 15:33:35 EST 2003


On Mon, 17 Nov 2003, Frank Ramsay wrote:

> Does anyone know of a site that has good info on writing scripts that run
> interactive programs?
> None of these programs are X based, so I am hoping I can use scripts to
> perform simple "send X
> expect Y" type tests.

Have you looked into curses? I believe you just pretty much summed up what
it's designed to do -- automate work with interactive (screen-based)
programs like Lymx, Pine, Emacs, etc.

The other one I like is the `script` command. It basically acts as a proxy
between the terminal and the shell or program you're running, logging all
keyed activity for later use: the output is a file that you can play back
to attempt to replicate everything you did through the `script` session.

Sometimes the output file from `script` gathers more than you intended.
For example, I made a typo on the word 'more' a few words back, so the
`script` output from this mail session would have something like
"mord^He". Likewise, if I use the arrow keys to move around the message as
I'm typing it (I just inserted a paragraph break before 'Sometimes', for
example) then that all gets recorded as well.

As a result, the output will bring you to not just the final result, but
all the little steps & mis-steps taken along the way. On the other hand,
you can edit this file (preferably with an editor that won't clobber any
non-printable-ascii data) to remove any extraneous steps, and if you're
feeling clear on the concept of how everything is logged (it's not *too*
confusing), you can manually type directly into the output file.

See if your system has the command -- on OSX it ships at /usr/bin/script,
but other systems may or may not include it. It's terribly useful if
you've got it available -- the one thing that might possibly be a pain for
your needs is the conditional "did the last step work?" testing that you
hint at, but this can probably be done as well.

Good luck :)


-- 
Chris Devers      cdevers at pobox.com
http://devers.homeip.net:8080/blog/

np: 'The Chase (Film Dialogue)'
     by Bob and Doug McKenzie
     from 'Strange Brew soundtrack'



More information about the Discuss mailing list