Prev: How do I automate standard input for interactive shell programs?
Next: Especial: DIGIPACK P/ CDs e DVDs
From: Bob Proulx on 3 Aug 2010 16:50 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. http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod 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! Bob |