FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.

» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

LinkBack Thread Tools
Old 08-03-2010, 08:40 PM
Bob Proulx
Default How do I automate standard input for interactive shell programs?

Timothy Legg wrote:
> I was bored. I was playing the worm game from bsdutils and through the
> tedium of it all, a thought passed through my mind. "Hey, this can be
> automated. By following a repetitive procedure, I can win the game - any
> time, every time!" It also occured to me that computers are very well
> suited for following repetitive steps, so I thought I would go about
> coding a solution.

There is another game like this too. It can keep the computer about
as busy. It is a little easier to write on the command line though.

$ yes | sha1sum


> I believe that having solonoid operated cursor keys is a bit overbuilt,
> clunky and is too much like a Goldberg machine for my taste. So I am
> looking for suggestions on how I can emulate a user at standard input
> pressing the cursor keys.

A "standard" tool for this task is 'expect'.

$ apt-cache show expect

Expect is a tool for automating interactive applications according
to a script. Following the script, Expect knows what can be
expected from a program and what the correct response should be.
Expect is also useful for testing these same applications. And by
adding Tk, you can also wrap interactive applications in X11 GUIs.
An interpreted language provides branching and high-level control
structures to direct the dialogue. In addition, the user can take
control and interact directly when desired, afterward returning
control to the script.

It is designed to spawn programs, expect certain output, send certain
input. It is based upon TCL. That is both good and bad. People will
certainly have opinions about TCL both ways. You might want to use
the Perl Expect module instead.

$ sudo apt-get install libexpect-perl

And then you can 'use Expect;' and proceed from there.


Or the Ruby or Python versions of the same. Then you would have Perl,
Ruby, Python and the full capabilities thereof (instead of TCL) to use
in the programming of your toy.

Good luck!


Thread Tools

All times are GMT. The time now is 12:42 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org