[TAG] Sending a keystroke to remote application
ben at callahans.org
Thu Jul 15 00:23:34 MSD 2004
On Wed, Jul 14, 2004 at 07:36:09PM +0100, Thomas Adam wrote:
> On Thu, 15 Jul 2004 02:24:55 +0800
> Nick Urbanik <nicku at vtc.edu.hk> wrote:
> > How can I send the "\r" to the remote application?
> Use 'expect'. It is why it was written. As an example:
> #!/usr/bin/expect -f
> # Created by Thomas Adam
> # First startup the application in question
> spawn <program_name> $arguments
> # When we reach this prompt....
> expect -re "Please insert DVD and press Enter"
> # Send a carriage return
> send "\r"
> # Allow control of the program back to the user
The easiest way to write an "expect" script is by letting "expect" do it
for you. The very first script in my /usr/share/doc/expect/examples is
"autoexpect"; when run by itself, it spawns a shell and records whatever
is done until you exit that shell. Conversely, you could type
autoexpect ssh joe at machine.com
and it will run your SSH session, recording everything you type in and
get back. I find that the result is very, very verbose (I've cut a
200-line script down to ~10 lines), but almost always useable.
* Ben Okopnik * okopnik.freeshell.org * Editor-in-Chief, Linux Gazette *
-*- See the Linux Gazette in its new home: <http://linuxgazette.net> -*-
More information about the TAG