Automatically filling in answers to interactive shell command questions

Erik Max Francis max at alcyone.com
Mon Jul 21 20:08:16 EDT 2003


Ted Weatherly wrote:

> Is it possible to use python to automatically fill in the answers to
> interactive shell command questions?  For example, I am using a shell
> command addperson that behaves as follows:
> 
>   > addperson
>   First Name: Ted
>   Birthday: 12/08/1977
>   Height: 6'0"
>   Location: San Francisco, CA
>   >
> 
> I am prompted for "First Name: " and I enter "Ted".  I am prompted for
> "Birthday: " and I enter "12/08/1977".  Imagine doing this for 100
> people or more...it gets tiresome.
> 
> Assuming I can't change the addperson command to read data from a
> file, is there any way to use python to fill in the data for the
> expected questions?  Perhaps a different language would be better?

expect was designed for this.  If the addperson program doesn't require
an interactive shell, you can get away with it with something as simple
as:

addperson <<EOF
Ted
12/08/1977
6'0"
San Francisco, CA
EOF

Or by putting these one per line in a file,

addperson < people.data

One certainly _could_ use Python for this, but in this case there are
probably better (and much simpler) tools for the job.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Behind an able man there are always other able men.
\__/  (a Chinese proverb)




More information about the Python-list mailing list