how to start a program using autoexpect

Kevin O'Gorman kogorman at gmail.com
Thu Jul 12 15:13:23 UTC 2012


On Thu, Jul 12, 2012 at 1:49 AM, user1 <bqz69 at telia.com> wrote:
>
>>
>> Your question is unclear.  You just started the program /bin/date in the
>> snippet in your email.  What more do you want?
>
> E.g. to start firefox or to start a bunch of programs after login
>
> The more I know the more ideas I get in future - ideas spawn new ideas in
> my brain.

I love Expect, but it is the wrong tool for that job.  Even if I were
to use it, autoexpect is an even stranger choice.

If I want to start a GUI program like firefox (browser), or pidgin
(chat), or CALibre (document repository), I would use bash (a shell).
So I suggest you learn more about the shell.  You are running one any
time you start a terminal program.  Just type something like
> firefox&
(That "&" detaches firefox from the shell so they run independently).

On the other hand, if you want to start a CLI program and direct it to
do several things, Expect is a reasonable tool.  It really shines,
however, at running multiple programs simultaneously, taking note when
any of them issues output and responding according to what it sees.

Autoexpect is a quick way to get an Expect script created.  Unless you
are doing  something exceedingly simple, the resulting script will
need to be edited.  The script generated by autoexpect can only handle
in the future the exact same results that were seen when you created
the script.  Anything else will cause the script to wedge or otherwise
fail.

Oh, and to start multiple programs, you would write a bash script thus:

====================== cut here ====================
#!/bin/bash

firefox&
pidgin&
calibre&
====================== cut here ====================

make that script executable, and run it when needed.  You can get it
executed on login by editing the startup scripts in your home
directory.  Bash can be set up in various ways, but on Ubuntu you'd
want to start with .profile or .bashrc.

====================== add this to .bashrc (at the end) =====================
# Put your fun stuff here.
if [ -e ~/.mybashrc ]
then
    source ~/.mybashrc
fi
====================== end =========================================
then create .mybashrc, and put any commands you like in it.

> I am experimenting to learn - hoping others will learn from this list :-)

If you want to become good at this, experimenting will take forever.
You need to do some serious reading.  There are tutorials on the web,
I'm sure.

-- 
Kevin O'Gorman, PhD




More information about the ubuntu-users mailing list